Memory

EsBufferRead

const void *EsBufferRead(EsBuffer *buffer, size_t readBytes);

Returns a pointer to readBytes in the buffer and advances the position. Returns null on error. The pointer is only valid while the buffer is unchanged.

EsBufferReadInto

bool EsBufferReadInto(EsBuffer *buffer, void *destination, size_t readBytes);

Copies readBytes from the buffer to destination. Returns false on error.

EsBufferReadMany

const void *EsBufferReadMany(EsBuffer *buffer, size_t a, size_t b);

Like EsBufferRead, but for a * b bytes. Returns null if the multiplication overflows.

EsBufferReadInt32Endian

int32_t EsBufferReadInt32Endian(EsBuffer *buffer, int32_t errorValue);

Reads an int32, converting byte order if big endian. Returns errorValue if there is not enough data.

EsBufferWrite

void *EsBufferWrite(EsBuffer *buffer, const void *source, size_t writeBytes);

Writes writeBytes to the buffer. For a memory-backed buffer, returns a pointer to the written data, or null on error; source may be null to zero the space. For a file-store-backed buffer, returns null and source must not be null; check buffer->error for errors.

EsBufferWriteInt8

bool EsBufferWriteInt8(EsBuffer *buffer, int8_t value);

Writes an int8 to the buffer. Returns true on error.

EsBufferWriteInt32Endian

bool EsBufferWriteInt32Endian(EsBuffer *buffer, int32_t value);

Changes byte order if big endian.

EsBufferFormat

void EsBufferFormat(EsBuffer *buffer, EsCString format, ...);

Appends.

EsBufferFormatV

void EsBufferFormatV(EsBuffer *buffer, EsCString format, va_list arguments);

Appends.

EsBufferFlushToFileStore

void EsBufferFlushToFileStore(EsBuffer *buffer);

Appends the buffered data to the buffer's file store and resets the position. The buffer must have a file store.

EsConstantBufferCreate

EsHandle EsConstantBufferCreate(const void *data, size_t dataBytes, EsHandle targetProcess);

Creates a constant buffer containing a copy of data. Returns a handle valid in targetProcess; use ES_CURRENT_PROCESS for the current process.

EsConstantBufferRead

void EsConstantBufferRead(EsHandle constantBuffer, void *output);

Copies the contents of the constant buffer to output.

EsConstantBufferShare

EsHandle EsConstantBufferShare(EsHandle constantBuffer, EsHandle targetProcess);

Creates a handle to the constant buffer in targetProcess.

EsConstantBufferGetSize

size_t EsConstantBufferGetSize(EsHandle constantBuffer);

Returns the size of the constant buffer.

EsHeapAllocate

void *EsHeapAllocate(size_t size, bool zeroMemory, EsHeap *heap = ES_NULL);

Allocates size bytes from the heap, zeroed if zeroMemory is true. Returns null on failure. Free with EsHeapFree.

EsHeapFree

void EsHeapFree(void *address, size_t expectedSize = 0, EsHeap *heap = ES_NULL);

Frees memory allocated with EsHeapAllocate. expectedSize may be 0.

EsHeapReallocate

void *EsHeapReallocate(void *oldAddress, size_t newAllocationSize, bool zeroNewSpace, EsHeap *heap = ES_NULL);

Changes the size of an allocation. Returns the new address, or null on failure. Free with EsHeapFree.

EsHeapValidate

void EsHeapValidate();

Validates the heap. Panics if the heap is corrupt.

EsMemoryCreateShareableRegion

EsHandle EsMemoryCreateShareableRegion(size_t bytes);

Creates a shareable memory region of bytes bytes. Returns a handle to the region.

EsMemoryCommit

bool EsMemoryCommit(void *pointer, size_t bytes);

Commits pages in a reserved region. pointer and bytes must be page-aligned. Returns true on success.

EsMemoryCompare

int EsMemoryCompare(const void *a, const void *b, size_t bytes);

Compares the two buffers. Returns a negative, zero, or positive value.

EsMemoryCopy

void EsMemoryCopy(void *destination, const void *source, size_t bytes);

Copies bytes from source to destination. Does not handle overlapping regions; use EsMemoryMove for overlaps.

EsMemoryCopyReverse

void EsMemoryCopyReverse(void *_destination, const void *_source, size_t bytes);

Copies bytes from the end of source to the end of destination.

EsMemoryDecommit

bool EsMemoryDecommit(void *pointer, size_t bytes);

May fail in low-memory conditions when the commit ranges on the region are fragmented. (Cannot fail if you decommit the entire region.)

EsMemoryFaultRange

void EsMemoryFaultRange(const void *pointer, size_t bytes, uint32_t flags = ES_FLAGS_DEFAULT);

Simulate a page fault in each page in the range.

EsMemoryFill

void EsMemoryFill(void *from, void *to, uint8_t byte);

Fills the range from from (inclusive) to to (exclusive) with byte.

EsMemoryMove

void EsMemoryMove(void *_start, void *_end, intptr_t amount, bool zeroEmptySpace);

Moves the range from start to end by amount bytes. If zeroEmptySpace, the vacated bytes are zeroed.

EsMemoryReserve

void *EsMemoryReserve(size_t size, EsMemoryProtection protection = ES_MEMORY_PROTECTION_READ_WRITE, EsMemoryReserveFlags flags = ES_MEMORY_RESERVE_COMMIT_ALL);

Reserves memory. Returns the address, or null on failure. Free with EsMemoryUnreserve.

EsMemoryShare

EsHandle EsMemoryShare(EsHandle sharedMemoryRegion, EsHandle targetProcess, bool readOnly);

Creates a handle to the shared memory region in targetProcess, read-only if readOnly is true.

EsMemorySumBytes

uint8_t EsMemorySumBytes(uint8_t *data, size_t bytes);

Returns the sum of all the bytes in data.

EsMemoryUnreserve

void EsMemoryUnreserve(void *pointer, size_t size = 0);

Must cover the entire reserved region. Leave size 0 if you don't know the size.

EsMemoryZero

void EsMemoryZero(void *destination, size_t bytes);

Zeros bytes bytes at destination.

EsMemoryMapObject

void *EsMemoryMapObject(EsHandle object, uintptr_t offset, size_t size, EsMemoryMapFlags flags);

Maps a shared memory region or file into the address space. Returns a pointer, or null on failure. Unmap with EsMemoryUnreserve.