Collaboration diagram for Allocation/deallocation functions:
Defines | |
#define | LDK_CTALLOC(size) LDK::alloc<size>(__FILE__,__LINE__) |
Allocate size bytes of memory. | |
#define | LDK_CTTYPEALLOC(type, num) ((type*)LDK::alloc<sizeof(type)*num)>(__FILE__,__LINE__) |
Allocate sizeof(type)*num bytes of memory. | |
#define | LDK_RTALLOC(size) LDK::alloc(__FILE__,__LINE__,size) |
Allocate size bytes of memory. | |
#define | LDK_RTTYPEALLOC(type, num) ((type*)LDK::alloc(__FILE__,__LINE__,sizeof(type)*num)) |
Allocate sizeof(type)*num bytes of memory. | |
#define | LDK_REALLOC(mem, newSize) LDK::realloc(__FILE__,__LINE__,mem,newSize) |
re-allocate some memory using a run-time search for the best fit. | |
Functions | |
void | LDK::dealloc (void *mem) |
Free memory allocated with this system only. |
Pool chunkSizes are arranged like this:
depending on whether the value defined by LDK_MINCHUNKSIZE is a power of two or a power of two + 1/2 times the same power of two.
Compared to previous versions this release vastly improves memory wastage and scalability. LDK_HEAPSIZE_K can be set to 4 megs and LDK_MAXCHUNKSIZE to 2 megs without problem. There is a small runtime penalty for this scalabilty, and synthetic benchmarks that allocate tons of memory probably won't perform hugely better than malloc. It will perform much better in real programs.
Note that pools with a chunkSizes that are multiples of 16 bytes will return 16 byte aligned allocations, making the returned memory suitable for use with SSE vector operations.
In addition template functions are provided as subsitutes for new/delete operators. These functions exploit the fact that the compiler knows the size of the object being allocated.
WARNING: The only thread that may free memory is the thread that allocated it. This condition is asserted.
#define LDK_CTALLOC | ( | size | ) | LDK::alloc<size>(__FILE__,__LINE__) |
size | The number of bytes to allocate. |
BadAlloc | if there is not enough free memory. Uses a compile-time searched memory pool allocation if possible, otherwise falls back to a 16-byte aligned malloc. |
Definition at line 736 of file Memory.h.
Referenced by LDK::Allocator< T >::allocate().
#define LDK_CTTYPEALLOC | ( | type, | |||
num | ) | ((type*)LDK::alloc<sizeof(type)*num)>(__FILE__,__LINE__) |
type | The type to cast the returned pointer to. | |
num | The number of "type" to allocate. |
BadAlloc | if there is not enough free memory. Uses a compile-time searched memory pool allocation if possible, otherwise falls back to a 16-byte aligned malloc. Does not call constructors. One example use is to allocate an array of floats. |
#define LDK_REALLOC | ( | mem, | |||
newSize | ) | LDK::realloc(__FILE__,__LINE__,mem,newSize) |
mem | The memory to change the allocation size of. | |
newSize | The new allocation size. |
BadAlloc | if there is not enough free memory. The algoritm used does nothing if the requested size already fits in the real allocation size, and it will only re-allocate to a smaller block if the new requested size is <= 1/2 the size of the block currently used. WILL CAUSE CRASHES if used on memory allocated with normal malloc/calloc/realloc |
Definition at line 810 of file Memory.h.
Referenced by LDK::Allocator< T >::reallocate().
#define LDK_RTALLOC | ( | size | ) | LDK::alloc(__FILE__,__LINE__,size) |
size | The number of bytes to allocate. |
BadAlloc | if there is not enough free memory. Uses a run-time searched memory pool allocation if possible, otherwise falls back to a 16-byte aligned malloc. |
Definition at line 764 of file Memory.h.
Referenced by LDK::Allocator< T >::_Charalloc(), and LDK::Allocator< T >::allocate().
#define LDK_RTTYPEALLOC | ( | type, | |||
num | ) | ((type*)LDK::alloc(__FILE__,__LINE__,sizeof(type)*num)) |
type | The type to cast the returned pointer to. | |
num | The number of "type" to allocate. |
BadAlloc | if there is not enough free memory. Uses a run-time searched memory pool allocation if possible, otherwise falls back to a 16-byte aligned malloc. Does not call constructors. One example use is to allocate an array of floats. |
void LDK::dealloc | ( | void * | mem | ) | [inline] |
mem | The memory to free. |
Definition at line 789 of file Memory.h.
References LDK::Singleton< T, StoragePolicy >::instance().
Referenced by LDK::create(), LDK::Allocator< T >::deallocate(), LDK::RawSmartPointer< T >::decRefCount(), and LDK::destroy().
Here is the call graph for this function: