Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site











SourceForge.net Logo

Heap

 

U++ has its own high-performance allocator that is finetuned for use with U++. Globals operators new/delete are normally overloaded to use this allocator, unless it is not possible or unless flagUSEMALLOC macro is defined (e.g. main package configuration contains USEMALLOC).

 

Basic allocation functions

 

void *MemoryAllocPermanent(size_t size)

Allocates a memory block of size bytes. This pointer is permanent and cannot be released, it is also ignored in leak checks.

 


 

void *MemoryAllocSz(size_t& size)

Allocates a memory block of at least size bytes. size is set to the real number of bytes in the block that can be used by an application. Guaranteed alignment is specified in UPP_HEAP_ALIGNMENT constant (currently 16). The minimal real size of returned block in release mode is UPP_HEAP_MINBLOCK (currently 32).

 


 

void *MemoryAlloc(size_t size)

Allocates a memory block of at least size bytes.

 


 

void MemoryFree(void *ptr)

Frees block previously allocated in MemoryAllocSz or MemoryAlloc.

 


 

void *MemoryAlloc32()

Allocates memory block of exactly 32 bytes. This has the same functionality as MemoryAlloc(32), but is slightly faster.

 


 

void MemoryFree32(void *ptr)

Frees a memory block previously allocated by MemoryAlloc32. This has the same functionality as MemoryFree(ptr), but is slightly faster.

 


 

void *MemoryAlloc48()

Allocates memory block of exactly 48 bytes. This has the same functionality as MemoryAlloc(32), but is slightly faster.

 


 

void MemoryFree48(void *ptr)

Frees a memory block previously allocated by MemoryAlloc48. This has the same functionality as MemoryFree(ptr), but is slightly faster.

 


 

bool MemoryTryRealloc(void *ptr, size_t& newsize)

Attempts to change the size of block at ptr to something closer to newsize. The real value is returned in newsize. Returns true on success.

 


 

void *TinyAlloc(int size)

Allocates the block of size bytes. This allows for allocation of smaller real size blocks (normally the minimal size of block returned is 32 bytes), but requires the block to be freed with TinyFree.

 


 

void TinyFree(int size, void *ptr)

Frees the block allocated with TinyAlloc, size has to be the same as during allocation.

 


 

template <class T, class... ArgsT *tiny_new(Args... args)

Allocates single object with TinyAlloc and initializes it (with placement new).

 


 

template <class Tvoid tiny_delete(T *ptr)

Deletes object allocated with tiny_new.

 

Heap diagnostics

 

size_t GetMemoryBlockSize(void *ptr)

Returns the size of block in bytes.

 


 

void MemoryCheck()

Checks the heap for any errors (caused by e.g. buffer overrides).

 


 

void MemoryDumpLarge()

Dumps a list of large allocations (1-64KB) to the standard log.

 


 

void MemoryDumpHuge()

Dups a list of huge allocations (normally 64KB - 16MB) to the standard log.

 


 

int MemoryUsedKb()

Returns the currently used memory.

 


 

int MemoryUsedKbMax()

Returns the peak memory usage.

 


 

void MemoryLimitKb(int kb)

This debug / diagnostics function limits memory usage to kb KBs. If the application allocates more, it stops with error.

 

Heap tuning

 

Heap tuning is provided through MemoryOptions class. Constructor of this class sets the default values to individual parameters, destructor applies them to the heap subsystem.

Last edit by oblivion on 04/13/2020. Do you want to contribute?. T++