I’m trying to embed binary media resources into source code. I will going to use plain C-array (char[]) to store binary. (with something like this: Embedding binary blobs using gcc mingw) Because managing media files resource separately is very annoying work because the symbol it is hard to determined at compile time, and makes my customers annoying too.
Anyway what I’m concerning is memory consuming. If I store a PNG image, actually, I don’t need the persistent binary anymore after I loaded live image instance (UIImage*) from it. But I think the persistent binary will remain in memory because
- it’s part of code
- and it’s constant.
I don’t know any option to remove it from memory.
How can I let a C-array always to be accessed from disk directly instead of remaining in memory?
PS.
I can limit my build and execution environment strictly. I will use Clang and the program will be run on iOS. Anyway I don’t mind to use any of extra build tool 🙂
I don’t fully understand what you are saying or trying to solve, but it sounds like you are looking for memory mapping. See
man mmap.ps reading again, if I understand your question correctly, you want to make a fat binary containing all resource data. In that case, the OS will probably page out unused parts of it, so the memory is “freed” automatically. (“freed” in the sense of releasing physical memory that can be used for other purposes) So the persistant binary will remain in virtual memory, but not in physical memory.
update to explain a little further
On your Mac, in the terminal, run
This will show the virtual memory mapping for your shell, showing total memory and resident memory. You will see this line:
This says, that in this region of memory the file
/bin/bashis to be found (memory mapped, again, seeman mmap) and that it is not fully paged in; only 460kb of the binary is actually present in memory. Which is interesting because this is the binary actually running. The other lines are interesting as well, but beyond the scope of this question.so if the OS of choice (iOS) has sane memory management, your problem does not really exist. Just don’t touch memory you don’t need to use; every time you touch it, the pages are read in memory.