ML Reference
|
Contents |
|
The memory manager is the library to manage memory blocks of significant sizes, which are allocated by different libraries, e.g. the ML, the GVR. This makes it possible to keep the accumulated size of the cached memory block accross all libraries in an application below a certain limit. This reduces the slow process of swapping memory to disk.
The memory manager can allocate memory blocks of random size, but it does not return the memory block to the user. Instead it returns a strong handle for the memory block, which grants access to the data pointer of the memory block. The memory block size adds to the size of locked memory, which is tracked by the memory manager. After the data has been used, the memory handle may be turned into a weak handle. This appends the memory block to the cache list of the memory manager (provided that no other strong handle for the memory block exists). The locked memory size is decreased and the cache size increased.
If neither weak handles nor strong handles reference a memory block, then it is deleted immediately. To access a cached memory block again, the weak handle is simply assigned to a strong handle. This causes the removal of the memory block from the cache list automatically.
If the accumulated sizes of the memory blocks in the cache list exceed the "cache and locked memory size limit", then memory blocks are removed from the cache list and deleted, according to the least-recently-used principle.
The image below shows that the cache list contains only those memory blocks that are exclusively referenced by weak handles. The memory blocks, which exist outside the cache list, are always referenced by at least one strong handle and may also be referenced by weak handles.
The memory manager can be thread safely used, more precise the caching of the memory manager is thread safe. The thread safe operations include assignment of strong and weak handles, memory allocation and adding allocated memory.
All thread safe methods are listed in Thread-safe Classes and Functions.