3 ms·
I did iOS 3D game dev back in the 2G days where you only got 24MB of RAM to work in if you were lucky. Even in the later device with lots more memory, the amou
by corysama 4y ago
I did iOS 3D game dev back in the 2G days where you only got 24MB of RAM to work in if you were lucky. Even in the later device with lots more memory, the amount you could use before getting a memory warning was small and varied wildly depending on what the user had been doing recently before firing up your app.
One technique to handle this is mentioned in the article: We used read-only memory mapped files containing position-independent data structures. We did this for audio and animation data without notable hitches.
The big one though was making our meshes and textures hot-reloadable. Whenever we got a memory warning, we just deleted the OpenGL buffers for all of our meshes and textures and let them reload on-demand.
From the POV of the OS we were being a very well-behaved citizen. The OS asked us to reduce memory and we did so instantly and dramatically. Meanwhile, the OS was also issuing memory warnings to all of the background apps that were hogging large, unpredictable chunks of RAM. Those apps would end up killed by the OS in short order, freeing up memory for us.
Right each kill-wave, we would naturally get right back to filling RAM with even more meshes and textures, triggering another memory-warning with would free up even more mem for us!
Pretty quickly we'd have all of the memories and the warnings would slow down. Using PVRTC texture compression and tightly pack vertex formats meant we could have a lot of detail loaded. And, simple binary file formats with just `fread(whole file in one go)` as our I/O practice meant we could reload everything in 1/10th of a second.
- rodgerd 4y agoI am impressed at a noisy neighbour problem where the noisy neighbour convinces the noise control officer to evict everyone living next to them!
- Asooka 4y agoMaybe more interestingly - that is the correct behaviour from the user's POV. The application that the user is currently interacting with is given more resources and background processes are throttled and killed until the user is done with their one task. Not sure what the takeaway here is - a well-behaved program deserves to be given more resources? Foreground applications should be the last ones killed?
- kitsunesoba 4y agoIt's interesting, because some of this memory management behavior is still visible now. You can tell which apps are light on resources by how many hours/days they manage to remain in memory without being killed, and it's not unusual to see memory hog apps kill each other in multitasking.
- bee_rider 4y agoIt is almost a shame that we won’t get such lovely stories from this era of unlimited memory.
- gajjanag 4y agoUmm, Apple still sells devices with just 1 GB of RAM on them ;)