cohtml::IAllocator
On this page
Allocator interface used by Cohtml for all memory allocations. The user has to provide an object that implements this interface. Memory allocations in Cohtml are tagged, so the user knows the relative distribution of memory among subsystems.
#include <Library.h>
Public Functions
Name | |
---|---|
IAllocator() | |
virtual void * | Allocate(unsigned size, cohtml::MemTags::MemTagsType memtag) =0 Allocate size bytes. |
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. |
virtual void | Deallocate(void * ptr, cohtml::MemTags::MemTagsType memtag) =0 Deallocates the memory previously allocated by Allocate. |
virtual void * | AlignedAllocate(unsigned size, unsigned alignment, cohtml::MemTags::MemTagsType memtag) =0 Allocate size bytes whose alignment is specified by alignment. |
virtual void | AlignedDeallocate(void * ptr, cohtml::MemTags::MemTagsType memtag) =0 Deallocates the memory previously allocated by AlignedAllocate. |
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. |
virtual bool | VirtualFree(void * ptr, unsigned size, int flags, cohtml::MemTags::MemTagsType memtag) =0 Releases and decommits a memory region. |
virtual | ~IAllocator() |
Public Functions Documentation
function IAllocator
IAllocator()
function Allocate
virtual void * Allocate(
unsigned size,
cohtml::MemTags::MemTagsType memtag
) =0
Allocate size bytes.
Parameters:
- size the number of bytes to allocate
- memtag tag of the subsystem from which the request came
Return: the pointer to the beginning of newly allocated memory.
Warning: the memory must be aligned on 8
function Reallocate
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.
Parameters:
- ptr the pointer to the memory area to be reallocated
- size number of bytes to allocate
- memtag tag of the subsystem from which the request came
function Deallocate
virtual void Deallocate(
void * ptr,
cohtml::MemTags::MemTagsType memtag
) =0
Deallocates the memory previously allocated by Allocate.
Parameters:
- ptr the pointer to the memory to deallocate
- memtag tag of the subsystem from which the request came
function AlignedAllocate
virtual void * AlignedAllocate(
unsigned size,
unsigned alignment,
cohtml::MemTags::MemTagsType memtag
) =0
Allocate size bytes whose alignment is specified by alignment.
Parameters:
- size number of bytes to allocate
- alignment specifies the alignment
- memtag tag of the subsystem from which the request came
Return: the pointer to the beginning of newly allocated memory
Warning: when specified, memory alignment for allocations should be preserved
function AlignedDeallocate
virtual void AlignedDeallocate(
void * ptr,
cohtml::MemTags::MemTagsType memtag
) =0
Deallocates the memory previously allocated by AlignedAllocate.
Parameters:
- ptr the pointer to the memory to deallocate
- memtag tag of the subsystem from which the request came
function VirtualAllocate
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.
Parameters:
- hint address of the region to allocate. Address is rounded down to the nearest page boundary.
- size the size of the region, in bytes.
- protection specifies a protection type for the memory region
- flags type of the allocation (commit, reserve etc)
- memtag tag of the subsystem from which the request came
Return: address of the allocated memory region.
Note: the return address must be aligned with the system page size
Warning: all newly committed memory by the provided implementation should be zeroed out
function VirtualFree
virtual bool VirtualFree(
void * ptr,
unsigned size,
int flags,
cohtml::MemTags::MemTagsType memtag
) =0
Releases and decommits a memory region.
Parameters:
- ptr a pointer to the address of the memory region.
- size the size of the region in bytes.
- flags type of the allocation (decommit, release etc).
- memtag tag of the subsystem from which the request came
Return: true if the function succeeds, otherwise false.`
function ~IAllocator
virtual ~IAllocator()