Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cHeap Struct Reference

#include <cHeap.h>

Inheritance diagram for Gray::cHeap:
Gray::cHeapAlign

Public Types

enum  FILL_TYPE {
  FILL_AllocStack = 0xCC , FILL_Alloc = 0xCD , FILL_Freed = 0xDD , FILL_AlignTail = 0xBD ,
  FILL_UnusedStack = 0xFE , FILL_Prefix = 0xFD
}
 

Static Public Member Functions

static UINT64 __stdcall get_PhysTotal ()
 
static UINT64 __stdcall get_PhysAvail ()
 
static void __stdcall Init (int nFlags=0)
 
static bool __stdcall Check ()
 
static size_t __stdcall GetSize (const void *pData) noexcept
 
static bool __stdcall IsValidHeap (const void *pData) noexcept
 
static bool IsCorruptHeap (const void *pData) noexcept
 
static bool __stdcall IsValidInside (const void *pData, ptrdiff_t index) noexcept
 
static void *__stdcall AllocPtr (size_t nSize)
 
static void * AllocPtr (size_t nSize, const void *pDataInit)
 
static void __stdcall FreePtr (void *pData)
 
static void *__stdcall ReAllocPtr (void *pData, size_t nSize)
 

Static Public Attributes

static const size_t k_ALLOC_MAX = 0x1000000
 256 * 64K = (arbitrary) largest reasonable single malloc. More...
 
static ITERATE_t sm_nAllocs = 0
 count total allocations (i.e. Number of calls to malloc() minus calls to free()) More...
 

Friends

class cHeapTests
 

Detailed Description

A static name space for applications main heap allocation/free related functions.

Note
Turning on the _DEBUG heap automatically uses _malloc_dbg() _DEBUG will put header and footer info on each heap allocation.

Member Enumeration Documentation

◆ FILL_TYPE

Debug Heap fill bytes.

Enumerator
FILL_AllocStack 

allocated on the stack in debug mode.

FILL_Alloc 

filled to indicate malloc() memory in debug mode.

FILL_Freed 

filled to indicate free() has been called on this.

FILL_AlignTail 

Fills the m_TailGap _DEBUG ONLY.

FILL_UnusedStack 

_DEBUG vsnprintf fills unused space with this.

FILL_Prefix 

Fills the gap before the returned memory block. _DEBUG ONLY.

Member Function Documentation

◆ AllocPtr() [1/2]

void *GRAYCALL Gray::cHeap::AllocPtr ( size_t  nSize)
static

Allocate a block of memory on the application heap. assume nothing about its current contents. uninitialized. Same footprint as C malloc() 0 size is allowed for some reason. (maybe returns NON nullptr)

◆ AllocPtr() [2/2]

static void* Gray::cHeap::AllocPtr ( size_t  nSize,
const void *  pDataInit 
)
inlinestatic

Allocate memory then copy stuff into it.

◆ Check()

bool GRAYCALL Gray::cHeap::Check ( )
static

Explicitly check the heap for consistency, validity. Assert if the memory check fails. called automatically every so often if (_CRTDBG_CHECK_ALWAYS_DF,_CRTDBG_CHECK_EVERY_16_DF,_CRTDBG_CHECK_EVERY_128_DF,etc)

Returns
false = failure.

◆ FreePtr()

void GRAYCALL Gray::cHeap::FreePtr ( void *  pData)
static

free a pointer to a block allocated on the heap. Same footprint as C free()

◆ get_PhysAvail()

UINT64 GRAYCALL Gray::cHeap::get_PhysAvail ( )
static

get total physical memory that might be avail to this process. UINT64 same as size_t for 64bit

◆ get_PhysTotal()

UINT64 GRAYCALL Gray::cHeap::get_PhysTotal ( )
static
Returns
total physical memory for this system. UINT64 same as size_t for 64bit

◆ GetSize()

size_t GRAYCALL Gray::cHeap::GetSize ( const void *  pData)
staticnoexcept

get the actual allocated size of a memory block in bytes.

Note
linux = Not always the size of the allocation request. maybe greater. _WIN32 = exact same size as requested malloc(),

◆ Init()

void GRAYCALL Gray::cHeap::Init ( int  nFlags = 0)
static

Initialize the heap to debug if desired.

  • nFlags = _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF _CRTDBG_CHECK_ALWAYS_DF = auto call _CrtCheckMemory on every alloc or free. _crtDbgFlag

◆ IsCorruptHeap()

static bool Gray::cHeap::IsCorruptHeap ( const void *  pData)
inlinestaticnoexcept

is this NOT a valid malloc() heap pointer?

Note
this should only ever be used in debug code. and only in an ASSERT.

◆ IsValidHeap()

bool GRAYCALL Gray::cHeap::IsValidHeap ( const void *  pData)
staticnoexcept

is this a valid malloc() heap pointer?

Note
this should only ever be used in debug code. and only in an ASSERT.

◆ IsValidInside()

bool GRAYCALL Gray::cHeap::IsValidInside ( const void *  pData,
ptrdiff_t  index 
)
staticnoexcept

Is this offset inside the valid heap block.

Note
this should only ever be used in debug code. and only in an ASSERT.

◆ ReAllocPtr()

void *GRAYCALL Gray::cHeap::ReAllocPtr ( void *  pData,
size_t  nSize 
)
static

allocate a different sized block but preserve existing content. Same footprint as C realloc()

Friends And Related Function Documentation

◆ cHeapTests

friend class cHeapTests
friend

Member Data Documentation

◆ k_ALLOC_MAX

const size_t Gray::cHeap::k_ALLOC_MAX = 0x1000000
static

256 * 64K = (arbitrary) largest reasonable single malloc.

◆ sm_nAllocs

ITERATE_t Gray::cHeap::sm_nAllocs = 0
static

count total allocations (i.e. Number of calls to malloc() minus calls to free())


The documentation for this struct was generated from the following files: