There is, it's called static. Just hide it in a .cpp file and expose the real function in a header file.
"Memory mapped files work by mapping the full file into a virtual address space and then using page faults to determine which chunks to load into physical memory. In essence it allows you to access the file as if you had read the whole thing into memory, without actually doing so."
I feel like this could be done in c++ directly, by maintaining an internal cache for each file that keeps track of which parts of the file are loaded and uses read() to load chunks on demand. Error handling would be a lot simpler (no signals, just a failed read()) and there would be less OS-specific code. AudioStream *AudioStreamBuilder::build() {
AudioStream *stream = nullptr;
if (mAudioApi == AudioApi::AAudio && isAAudioSupported()) {
stream = new AudioStreamAAudio(*this);
// If unspecified, only use AAudio if recommended.
} else if (mAudioApi == AudioApi::Unspecified && isAAudioRecommended()) {
stream = new AudioStreamAAudio(*this);
} else {
if (getDirection() == oboe::Direction::Output) {
stream = new AudioOutputStreamOpenSLES(*this);
} else if (getDirection() == oboe::Direction::Input) {
stream = new AudioInputStreamOpenSLES(*this);
}
}
return stream;
}
Result AudioStreamBuilder::openStream(AudioStream **streamPP) {
if (streamPP == nullptr) {
return Result::ErrorNull;
}
*streamPP = nullptr;
AudioStream *streamP = build();
if (streamP == nullptr) {
return Result::ErrorNull;
}
Result result = streamP->open(); // TODO review API
if (result == Result::OK) {
*streamPP = streamP;
}
return result;
}
Doesn't this leak memory if streamP->open() fails? I'm also surprised they are using new instead of unique_ptr, especially since one of their listed benefits is "Convenient C++ API (uses the C++11 standard) ".