cohtml::IVirtualAllocator

Virtual memory allocator interface used by Cohtml for scripting memory allocations.

#include <Library.h>

Public Functions

Name
IVirtualAllocator()
virtual~IVirtualAllocator()
virtual size_tGetAllocationPageSize() const =0
virtual size_tGetCommitPageSize() const =0
virtual void *Allocate(void * address, size_t size, size_t alignment, int protection, int flags) =0
Reserve and/or commit a memory region.
virtual boolFree(void * address, size_t size, int flags) =0
Releases or decommits a memory region.
virtual boolPartialFree(void * address, size_t oldSize, size_t newSize, int flags) =0
Releases or decommits part of a memory region.

Public Functions Documentation

function IVirtualAllocator

IVirtualAllocator()

function ~IVirtualAllocator

virtual ~IVirtualAllocator()

function GetAllocationPageSize

virtual size_t GetAllocationPageSize() const =0

Return: the page granularity for reserving memory.

function GetCommitPageSize

virtual size_t GetCommitPageSize() const =0

Return: the page granularity for committing memory.

function Allocate

virtual void * Allocate(
    void * address,
    size_t size,
    size_t alignment,
    int protection,
    int flags
) =0

Reserve and/or commit a memory region.

Parameters:

  • address a hint when reserving memory and a concrete address when committing.
  • size the number of bytes to allocate.
  • alignment the required alignment for the return address.
  • protection specifies a protection type for the memory region.
  • flags type of the allocation (commit, reserve or reserve & commit).

Return: address of the allocated memory region.

function Free

virtual bool Free(
    void * address,
    size_t size,
    int flags
) =0

Releases or decommits a memory region.

Parameters:

  • address a concrete address to release or decommit.
  • size the number of bytes to deallocate.
  • flags type of the deallocation (decommit or release).

Return: true if the function succeeds, otherwise false.

Note: A release call is expected to also decommit the memory.

function PartialFree

virtual bool PartialFree(
    void * address,
    size_t oldSize,
    size_t newSize,
    int flags
) =0

Releases or decommits part of a memory region.

Parameters:

  • address a address of the start of the region.
  • oldSize the original size of the region
  • newSize the new size of the region
  • flags type of the deallocation (decommit or release).

Return: true if the function succeeds, otherwise false.

Note:

  • A release call is expected to also decommit the memory.
  • Some platforms (like Microsoft Windows) may not support partial release of reserved regions. On these platforms, only decommit this memory and wait for a final release. However, the final release will use newSize as size of the memory to be released. At least on Microsoft Windows this is ok, since it releases the whole memory region, ignoring the size.