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

Developer

resources

Internal heap management

Many developers protect against fragmentation by implementing their own heap managers. The basic approach is to request a large amount of memory from Brew during application initialization, then satisfy any later allocation requests from that initial pool. The advantage to this approach is that it allows an application to determine at initialization time whether it has enough memory to run, and to guarantee that no other application or system API will take that memory away or fragment it.

Heap managers are often implemented so that they allocate a single large block during initialization, and fail if that allocation request can not be satisfied. This type of implementation is not recommended, as other Brew applications may have fragmented the heap such that no sufficiently large, contiguous block exists. Instead, the developer should determine the largest contiguous block that the application will actually need, and then implement the heap manager so it can compose its heap out of multiple sufficiently large blocks.

This approach can be an effective way to ensure that an application can run under predictable conditions, but it does not improve efficiency in memory utilization. Applications that require large amounts of memory or perform frequent allocations, such as web browsers and games, should strongly consider this approach.