Anonymous SHared MEMory, or ASHMEM, is a named memory block that is shared between processes that the kernel is allowed to free. This is notable as the kernel is not allowed to free standard shared memory.
ASHMEM is allocated and used as follows:
fd = ashmem_create_region("my_shm_region", size);
if(fd < 0)
return -1;
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if(data == MAP_FAILED)
goto out;
However for security reasons other processes cannot access this region by name (my_shm_region). The file descriptor pointing to this shared memory region is actually passed through the IPC Binding interface. Concrete examples found in IMemory.h.
Source: Android Platform Google Groups http://bit.ly/1vnP69
ASHMEM vs PMEM: "ashmem and pmem are very similar. Both are used for sharing memory between processes. ashmem uses virtual memory, whereas pmem uses physically contiguous memory. One big difference is that with ashmem, you have a ref-counted object that can be shared equally between processes. For example, if two processes are sharing an ashmem buffer, the buffer reference goes away when both process[es] have removed all their references by closing all their file descriptors. pmem doesn't work that way because it needs to maintain a physical to virtual mapping of. This requires the process that allocates a pmem heap to hold the file descriptor until all the other references are closed.
[...] The choice between ashmem and pmem Payment Gateways depends on whether you need physically contiguous buffers. In the case of the G1 [T-Mobile's Android phone], we use the hardware 2D engine to do scaling, rotation, and color conversion, so we use pmem heaps. The emulator doesn't have a pmem driver and doesn't really need one, so we use ashmem in the emulator. If you use ashmem on the G1, you lose the hardware 2D engine capability [...]"
Source: android-framework mailing list http://bit.ly/Jk7HP
The Java-based high-level ASHMEM wrapper: http://developer.android.com/reference/android/os/MemoryFile.html
www.backgroundnow.com
Comments (0)
You don't have permission to comment on this page.