mirror of
https://github.com/nicbarker/clay.git
synced 2025-09-18 04:26:18 +00:00
[Core] Align base arena memory to 64 byte cache line
This commit is contained in:
parent
6f10bf4b3d
commit
b9e27178c0
13
clay.h
13
clay.h
|
@ -1284,15 +1284,12 @@ struct Clay_Context {
|
||||||
|
|
||||||
Clay_Context* Clay__Context_Allocate_Arena(Clay_Arena *arena) {
|
Clay_Context* Clay__Context_Allocate_Arena(Clay_Arena *arena) {
|
||||||
size_t totalSizeBytes = sizeof(Clay_Context);
|
size_t totalSizeBytes = sizeof(Clay_Context);
|
||||||
uintptr_t memoryAddress = (uintptr_t)arena->memory;
|
if (totalSizeBytes > arena->capacity)
|
||||||
// Make sure the memory address passed in for clay to use is cache line aligned
|
|
||||||
uintptr_t nextAllocOffset = (memoryAddress % 64);
|
|
||||||
if (nextAllocOffset + totalSizeBytes > arena->capacity)
|
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
arena->nextAllocation = nextAllocOffset + totalSizeBytes;
|
arena->nextAllocation += totalSizeBytes;
|
||||||
return (Clay_Context*)(memoryAddress + nextAllocOffset);
|
return (Clay_Context*)(arena->memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
Clay_String Clay__WriteStringToCharBuffer(Clay__charArray *buffer, Clay_String string) {
|
Clay_String Clay__WriteStringToCharBuffer(Clay__charArray *buffer, Clay_String string) {
|
||||||
|
@ -3990,6 +3987,10 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
|
||||||
|
|
||||||
CLAY_WASM_EXPORT("Clay_Initialize")
|
CLAY_WASM_EXPORT("Clay_Initialize")
|
||||||
Clay_Context* Clay_Initialize(Clay_Arena arena, Clay_Dimensions layoutDimensions, Clay_ErrorHandler errorHandler) {
|
Clay_Context* Clay_Initialize(Clay_Arena arena, Clay_Dimensions layoutDimensions, Clay_ErrorHandler errorHandler) {
|
||||||
|
// Cacheline align memory passed in
|
||||||
|
uintptr_t baseOffset = 64 - ((uintptr_t)arena.memory % 64);
|
||||||
|
baseOffset = baseOffset == 64 ? 0 : baseOffset;
|
||||||
|
arena.memory += baseOffset;
|
||||||
Clay_Context *context = Clay__Context_Allocate_Arena(&arena);
|
Clay_Context *context = Clay__Context_Allocate_Arena(&arena);
|
||||||
if (context == NULL) return NULL;
|
if (context == NULL) return NULL;
|
||||||
// DEFAULTS
|
// DEFAULTS
|
||||||
|
|
Loading…
Reference in a new issue