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











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord 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.

 


 

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.

 


 

dword MemoryGetCurrentSerial()

In debug mode, returns the serial number of the next allocated block. This number is eventually listed in the log in case there are any leaks.

 


 

void MemoryIgnoreNonMainLeaks()

Makes leaks detector ignore leaks by global constructors.

 


 

void MemoryIgnoreNonUppThreadsLeaks()

Makes leaks dectector ignore leaks created by threads that are not launched by U++ Thread class.

 


 

void MemoryIgnoreLeaksBegin()

Makes leak detector ignore leaks of blocks allocated until MemoryIgnoreLeaksEnd is called. Calls can be nested. This is especially useful when working with 3rd party code that might e.g. create static leaks (memory is allocated just once, but library does not bother to deallocate on exit).

 


 

void MemoryIgnoreLeaksEnd()

Ends the suppression started by MemoryIgnoreLeaksBegin.

 


 

struct MemoryIgnoreLeaksBlock

This helper class calls MemoryIgnoreLeaksBegin in constructor and MemoryIgnoreLeaksEnd, in other works supresses leaks till the end of block.

 

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.

Do you want to contribute?