1.26.2.1
Gameface
cohtml::IAllocator Class Referenceabstract

Allocator interface used by Cohtml for all memory allocations. The user has to provide an object that imlements this interface. Memory allocations in Cohtml are tagged, so the user knows the relative distribution of memory among subsystems. More...

Public Member Functions

 IAllocator ()
 
virtual void * Allocate (unsigned size, cohtml::MemTags::MemTagsType memtag)=0
 Allocate size bytes. More...
 
virtual void * Reallocate (void *ptr, unsigned size, cohtml::MemTags::MemTagsType memtag)=0
 Reallocates the given area of memory. It must be previously allocated by Allocate. More...
 
virtual void Deallocate (void *ptr, cohtml::MemTags::MemTagsType memtag)=0
 Deallocates the memory previously allocated by Allocate. More...
 
virtual void * AlignedAllocate (unsigned size, unsigned alignment, cohtml::MemTags::MemTagsType memtag)=0
 Allocate size bytes whose alignment is specified by alignment. More...
 
virtual void AlignedDeallocate (void *ptr, cohtml::MemTags::MemTagsType memtag)=0
 Deallocates the memory previously allocated by AlignedAllocate. More...
 
virtual void * VirtualAllocate (void *hint, unsigned size, int protection, int flags, cohtml::MemTags::MemTagsType memtag)=0
 Reserves, commits, or changes the state of a memory region. More...
 
virtual bool VirtualFree (void *ptr, unsigned size, int flags, cohtml::MemTags::MemTagsType memtag)=0
 Releases and decommits a memory region. More...
 
virtual ~IAllocator ()
 

Detailed Description

Allocator interface used by Cohtml for all memory allocations. The user has to provide an object that imlements this interface. Memory allocations in Cohtml are tagged, so the user knows the relative distribution of memory among subsystems.

Constructor & Destructor Documentation

◆ IAllocator()

cohtml::IAllocator::IAllocator ( )

◆ ~IAllocator()

virtual cohtml::IAllocator::~IAllocator ( )
virtual

Member Function Documentation

◆ AlignedAllocate()

virtual void* cohtml::IAllocator::AlignedAllocate ( unsigned  size,
unsigned  alignment,
cohtml::MemTags::MemTagsType  memtag 
)
pure virtual

Allocate size bytes whose alignment is specified by alignment.

Parameters
sizenumber of bytes to allocate
alignmentspecifies the alignment
memtagtag of the subsystem from which the request came
Returns
the pointer to the beginning of newly allocated memory
Warning
when specified, memory alignment for allocations should be perserved

◆ AlignedDeallocate()

virtual void cohtml::IAllocator::AlignedDeallocate ( void *  ptr,
cohtml::MemTags::MemTagsType  memtag 
)
pure virtual

Deallocates the memory previously allocated by AlignedAllocate.

Parameters
ptrthe pointer to the memory to deallocate
memtagtag of the subsystem from which the request came

◆ Allocate()

virtual void* cohtml::IAllocator::Allocate ( unsigned  size,
cohtml::MemTags::MemTagsType  memtag 
)
pure virtual

Allocate size bytes.

Parameters
sizethe number of bytes to allocate
memtagtag of the subsystem from which the request came
Returns
the pointer to the beginning of newly allocated memory.
Warning
the memory must be aligned on 8

◆ Deallocate()

virtual void cohtml::IAllocator::Deallocate ( void *  ptr,
cohtml::MemTags::MemTagsType  memtag 
)
pure virtual

Deallocates the memory previously allocated by Allocate.

Parameters
ptrthe pointer to the memory to deallocate
memtagtag of the subsystem from which the request came

◆ Reallocate()

virtual void* cohtml::IAllocator::Reallocate ( void *  ptr,
unsigned  size,
cohtml::MemTags::MemTagsType  memtag 
)
pure virtual

Reallocates the given area of memory. It must be previously allocated by Allocate.

Parameters
ptrthe pointer to the memory area to be reallocated
sizenumber of bytes to allocate
memtagtag of the subsystem from which the request came

◆ VirtualAllocate()

virtual void* cohtml::IAllocator::VirtualAllocate ( void *  hint,
unsigned  size,
int  protection,
int  flags,
cohtml::MemTags::MemTagsType  memtag 
)
pure virtual

Reserves, commits, or changes the state of a memory region.

Parameters
hintaddress of the region to allocate. Address is rounded down to the nearest page boundary.
sizethe size of the region, in bytes.
protectionspecifies a protection type for the memory region
flagstype of the allocation (commit, reserve etc)
memtagtag of the subsystem from which the request came
Returns
address of the allocated memory region.
Note
the return address must be aligned with the system page size
Warning
all newly commited memory by the provided implementation should be zeroed out

◆ VirtualFree()

virtual bool cohtml::IAllocator::VirtualFree ( void *  ptr,
unsigned  size,
int  flags,
cohtml::MemTags::MemTagsType  memtag 
)
pure virtual

Releases and decommits a memory region.

Parameters
ptra pointer to the address of the memory region.
sizethe size of the region in bytes.
flagstype of the allocation (decommit, release etc).
memtagtag of the subsystem from which the request came
Returns
true if the function succeeds, otherwise false.`