whalloc  Update of "WhallocFallback"

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.


Artifact ID: 888b92b1c8b3f56ede1bda0a61f815cb0c1bc6f1
Page Name:WhallocFallback
Date: 2010-02-27 17:21:29
Original User: stephan
Parent: 01bf9447414676acdc88c40c3c0e8dfc5c24a331

Allocation fallback

By default, the allocators will fail if their pool does not contain enough contiguous memory to provide the requested allocation. However, some of the allocators have a member structure of type whalloc_fallback) with these members:

  • void * (*realloc)( void *, size_t size )
  • void (*free)( void * mem )

If either is set to non-null, both must be set to complementary functions. If they are non-null, the realloc member will be used to satisfy (re)allocation requests and the free member will be used to free any memory passed to the equivalent whalloc_XX_free() function which is not in the memory range reserved by the allocator. The allocators can decide, with a simple range comparison, whether or not a given address belongs to them, so they can "safely" pass on the call to free() (well, as safely as that gets, anyway).

For example, you could set the fallback to be the standard realloc(3) and free(3) functions. The easiest way to do that is:

myBtAllocator.base.fallback = whalloc_fallback_stdalloc;

However, that must be done before any allocations are made using the allocator object, ideally immediately after initialization (e.g., via whalloc_bt_init()).