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

Developer

resources

Movable memory blocks

When an application needs to retain allocated memory while suspended or backgrounded, those blocks should be marked as movable. When an allocated block is marked by the application as movable, it grants permission to the Brew heap manager to move that block to a new location in memory as needed. This means that if another Brew application requests a larger block of memory than can be allocated, Brew may be able to move some allocated blocks to reduce fragmentation and satisfy the request. When an application wishes to mark a block of memory as movable, it passes Brew the address of the pointer to that block. This way, Brew can change the location of the block, and update the value of the pointer transparently to the application.

If the application maintains more than one pointer to that block of memory, only one pointer will be updated. The application should ensure that the new address is propagated to all pointers to that memory block. Smart pointers may help in simplifying the management of pointers to movable memory blocks. In this approach, only a single reference to the actual memory block should ever exist, managed by the smart pointer. For more information on this feature see the API Reference documentation for the LOCKMEM() and UNLOCKMEM() APIs. Due to the restrictions using movable memory, and the effect of those restrictions on application performance, LOCKMEM() and UNLOCKMEM() should not be applied to every block of memory. Objects that are accessed multiple times per frame or created through ISHELL_CreateInstance/IEnv_CreateInstance would not be good candidates. This approach should be applied to objects with a long lifetime that are accessed infrequently. Data that must be retained while the application is suspended or backgrounded are good candidates.