Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Memory fragmentation

Memory fragmentation is the process by which a single, contiguous free-block of heap memory becomes broken up into a set of smaller, non-contiguous blocks, which are separated by arbitrarily sized used-blocks. This generally occurs when the adjacent blocks of memory have varying lifetimes. The following illustrates a sequence of allocations and deallocations that results in fragmented memory.

Note: Although the total amount of free memory in snapshots 2 and 4 is the same (32KB), the size of the largest free block has been reduced to 16KB. Because of this, the heap is now fragmented and any subsequent allocation request greater than 16KB will fail.

Brew MP management of fragmentation

Brew MP tracks memory by module. If an application allocates memory, that block of memory becomes free and available when the module assigned to that block is released (when the reference count of the module is zero). In certain situations, the Brew MP heap performs its own, automatic memory management to allocate, resize, and free space.

By default, Brew MP always responds to an allocation request with a contiguous block. Also by default, all memory allocated by the Brew MP heap is locked and cannot be relocated. As long as modules are getting the memory they need, Brew MP allows memory to become increasingly fragmented, but as soon as a module needs a larger block of memory than is currently available, the normal process of heap management locates and consolidates the movable blocks. It is not possible to force or interfere with this process; Brew MP executes it automatically.

Note: The process to free up memory is activated only by applications and events in the Brew MP context; applications and events written for OS Services are not subject to this process.

Applications can unlock and lock memory blocks using the UNLOCKMEM() and LOCKMEM() macros. For more information, see Memory helper macros.