Question

I'm looking into virtual memory management with android ndk and was wondering if there is an equivalent to the VirtualAlloc/Free family of functions in the android ndk, and if so, where can I find some docs on them.

Thank you for your time.

Was it helpful?

Solution

On Android, all memory allocations are "virtual", in the sense that the memory is not committed unless it is really accessed. If I remember correctly, VirtualAlloc comes from Windows CE, where the memory per process was artificially limited to 32 MByte (see http://denniskrabbe.wordpress.com/2009/10/09/windows-mobile-heaps-from-the-large-memory-area/). On Android, the limitations are the natural ones of a 32-bit architecture (iOS has recently entered the 64-bit era). There are some limitations on the JVM heap size, but they do not apply to native (NDK) memory (see Maximum native memory that can be allocated to an android app)

In Android, just like any Linux, malloc is optimistic, which means you can encounter out-of-memory after your malloc succeeded, see Does malloc lazily create the backing pages for an allocation on Linux (and other platforms)?. On the other hand, bionic does not provide custom memory allocation hooks as glibc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top