The Nebula Device 3: Memory Namespace Reference

The Nebula Device 3

Memory Namespace Reference


Detailed Description

The Nebula3 Memory subsystem implements custom memory allocation mechanisms which provide higher performance and better debugging aids.

Data Structures

struct  TotalMemoryStatus
class  PoolArrayAllocator
class  Heap
class  Memory
class  MemoryPool

Enumerations

enum  HeapType
enum  HeapType

Functions

void * Alloc (HeapType heapType, size_t size, size_t alignment=16)
 allocate a chunk of memory
void * Realloc (HeapType heapType, void *ptr, size_t size)
 re-allocate a chunk of memory
void Free (HeapType heapType, void *ptr)
 free a chunk of memory
char * DuplicateCString (const char *from)
 duplicate a C-string (obsolete)
bool IsOverlapping (const unsigned char *srcPtr, size_t srcSize, const unsigned char *dstPtr, size_t dstSize)
 check if 2 memory regions are overlapping
TotalMemoryStatus GetTotalMemoryStatus ()
void Copy (const void *from, void *to, size_t numBytes)
 copy a chunk of memory
void Clear (void *ptr, size_t numBytes)
 overwrite a chunk of memory with zero
void Fill (void *ptr, size_t numBytes, unsigned char value)
 fill memory with a specific byte
void SetupHeaps ()
const char * GetHeapTypeName (HeapType heapType)
__forceinline void CopyToGraphicsMemory (const void *from, void *to, size_t numBytes)
void * Alloc (HeapType heapType, size_t size)
 allocate a chunk of memory
void DumpTotalMemoryStatus ()
__forceinline unsigned char * __HeapAlignPointerAndWritePadding16 (unsigned char *ptr)
__forceinline unsigned char * __HeapUnalignPointer16 (unsigned char *ptr)
__forceinline LPVOID __HeapAlloc16 (HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
__forceinline LPVOID __HeapReAlloc16 (HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes)
__forceinline BOOL __HeapFree16 (HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
__forceinline SIZE_T __HeapSize16 (HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)

Variables

malloc_zone_t * Heaps [NumHeapTypes]
malloc_zone_t * Heaps [NumHeapTypes]
HANDLE volatile Heaps [NumHeapTypes] = { NULL }
HANDLE volatile Heaps [NumHeapTypes]

Enumeration Type Documentation

Heap types are defined here. The main purpose for the different heap types is to decrease memory fragmentation and to improve cache usage by grouping similar data together. Platform ports may define platform-specific heap types, as long as only platform specific code uses those new heap types.

Heap types are defined here. The main purpose for the different heap types is to decrease memory fragmentation and to improve cache usage by grouping similar data together. Platform ports may define platform-specific heap types, as long as only platform specific code uses those new heap types.


Function Documentation

void* Memory::Alloc ( HeapType  heapType,
size_t  size,
size_t  alignment = 16 
)

allocate a chunk of memory

Allocate a block of memory from one of the global heaps.

void* Memory::Realloc ( HeapType  heapType,
void *  ptr,
size_t  size 
)

re-allocate a chunk of memory

Re-Allocate a block of memory from one of the global heaps.

NOTE that this function may also be used to shrink a memory block!

void Memory::Free ( HeapType  heapType,
void *  ptr 
)

free a chunk of memory

Free a block of memory.

char * Memory::Memory::DuplicateCString ( const char *  from  ) 

duplicate a C-string (obsolete)

Duplicate a 0-terminated string, this method should no longer be used!

bool Memory::Memory::IsOverlapping ( const unsigned char *  srcPtr,
size_t  srcSize,
const unsigned char *  dstPtr,
size_t  dstSize 
)

check if 2 memory regions are overlapping

Test if 2 areas of memory areas are overlapping.

TotalMemoryStatus Memory::GetTotalMemoryStatus (  ) 

Get the system's total memory status.

void Memory::Copy ( const void *  from,
void *  to,
size_t  numBytes 
)

copy a chunk of memory

Copy a chunk of memory (note the argument order is different from memcpy()!!!)

void Memory::Clear ( void *  ptr,
size_t  numBytes 
)

overwrite a chunk of memory with zero

Overwrite a chunk of memory with 0's.

void Memory::Fill ( void *  ptr,
size_t  numBytes,
unsigned char  value 
)

fill memory with a specific byte

Fill memory with a specific byte.

void Memory::Memory::SetupHeaps (  ) 

Setup the global heaps.

const char * Memory::Memory::GetHeapTypeName ( HeapType  heapType  ) 

Returns a human readable name for a heap type.

__forceinline void Memory::CopyToGraphicsMemory ( const void *  from,
void *  to,
size_t  numBytes 
)

Copy data from a system memory buffer to graphics resource memory. Some platforms may need special handling of this case.

void* Memory::Alloc ( HeapType  heapType,
size_t  size 
)

allocate a chunk of memory

Allocate a block of memory from one of the global heaps.

void Memory::DumpTotalMemoryStatus (  ) 

Dump detail memory status information.

__forceinline unsigned char* Memory::__HeapAlignPointerAndWritePadding16 ( unsigned char *  ptr  ) 

Helper function for Heap16 functions: aligns pointer to 16 byte and writes padding mask to byte before returned pointer.

__forceinline unsigned char* Memory::__HeapUnalignPointer16 ( unsigned char *  ptr  ) 

Helper function for Heap16 functions: "un-aligns" pointer through the padding mask stored in the byte before the pointer.

__forceinline LPVOID Memory::__HeapAlloc16 ( HANDLE  hHeap,
DWORD  dwFlags,
SIZE_T  dwBytes 
)

HeapAlloc replacement which always returns 16-byte aligned addresses.

NOTE: only works for 32 bit pointers!

__forceinline LPVOID Memory::__HeapReAlloc16 ( HANDLE  hHeap,
DWORD  dwFlags,
LPVOID  lpMem,
SIZE_T  dwBytes 
)

HeapReAlloc replacement for 16-byte alignment.

NOTE: only works for 32 bit pointers!

__forceinline BOOL Memory::__HeapFree16 ( HANDLE  hHeap,
DWORD  dwFlags,
LPVOID  lpMem 
)

HeapFree replacement which always returns 16-byte aligned addresses.

NOTE: only works for 32 bit pointers!

__forceinline SIZE_T Memory::__HeapSize16 ( HANDLE  hHeap,
DWORD  dwFlags,
LPCVOID  lpMem 
)

HeapSize replacement function.


Variable Documentation

malloc_zone_t* Memory::Heaps[NumHeapTypes]

Heap pointers are defined here. Call ValidateHeap() to check whether a heap already has been setup, and to setup the heap if not.

malloc_zone_t* Memory::Heaps[NumHeapTypes]

Heap pointers are defined here. Call ValidateHeap() to check whether a heap already has been setup, and to setup the heap if not.

HANDLE volatile Memory::Heaps[NumHeapTypes] = { NULL }

Heap pointers are defined here. Call ValidateHeap() to check whether a heap already has been setup, and to setup the heap if not.

HANDLE volatile Memory::Heaps[NumHeapTypes]

Heap pointers are defined here. Call ValidateHeap() to check whether a heap already has been setup, and to setup the heap if not.