The main purpose is to isolate memory allocations. After forming a context from a memory block, allocator clients can be made. An allocator client can allocate memory from the original memory block in an isolated way. Destroying a client will free all memory allocated inside the client. This meant to efficiently reclaim memory if memory leak occured inside a client.
This mechanism is used i.e. for profiles and programs in the Welltype Virtual Machine.
Context can be created using the vmma_create_context() function. The VMMA context requires a single block of memory, with some configuration parameters, such as alignment and block size.
The behavior of the context can be altered by setting features on it. The libvmma.h defines the feature flags, but the library may was configured to omit some of them. To test the actual feature set, use the vmma_get_supported_flags(). The set flags on a context can be queried with vmma_get_accepted_flags(). The currently implemented features are:
After the context is made, it is ready to host allocator clients. The vmma_create_client() function meant to create a new client, that will have a separate space in the memory block of the context. This space is not necessarily continuous (see Allocation strategy below). The client can be completely freed up using the vmma_delete_client(). This also reclaims all memory blocks allocated using the specified client. The former memory blocks shall not be used after the vmma_delete_client() was called.
Memory blocks can be allocated from the client with vmma_alloc. These memory block can be freed using the vmma_free with the same context. The client can be tested whether it owns a memory block using the vmma_test_address(). Furthermore, the client can tell the actual size of an allocated memory block (if it allocated within the specified client) using the vmma_get_size().
Statistics can be queried from both the context and the client. These functions may return a precalculated value, like vmma_get_total_size(), or populates a dynamic property which takes some time, like vmma_populate_cached_blocks().
A buddy allocator context can be freed up behind the scenes, and will be reused to store memory blocks for a different client, or will be used to store administrative information. Thus, never access a memory block that was freed up.