Browse Source

add arenaGetAddressOffset helper

main
cinnaboot 5 years ago
parent
commit
c999f408b1
  1. 11
      src/util.h

11
src/util.h

@ -33,12 +33,15 @@ struct MemoryArena
MemoryArena* arenaInit(size_t initial_size = DEFAULT_ARENA_SIZE);
void arenaFree(MemoryArena*& arena);
u32 arenaGetFreeSize(MemoryArena* arena);
#define ARENA_ALLOC(arena, type, count) \
(type*) arenaAllocateBlock(arena, sizeof(type) * count)
void* arenaAllocateBlock(MemoryArena* arena, size_t block_size);
void* arenaGetAddressOffset(void* address, u32 offset);
#define MAX_NAME_LENGTH 256
char* arenaCopyCStr(MemoryArena* arena,
const char* input,
@ -46,7 +49,9 @@ char* arenaCopyCStr(MemoryArena* arena,
#define UTIL_ALLOC(count, type) (type*) utilAllocate(count, sizeof(type))
void* utilAllocate(u32 count, u32 type_size);
char* utilAllocateCStr(const char* str, u32 max_len = 256);
void utilSafeFree(void* p);
#endif // UTIL_H
@ -115,6 +120,12 @@ arenaAllocateBlock(MemoryArena* arena, size_t block_size)
return ret;
}
void*
arenaGetAddressOffset(void* address, u32 offset)
{
return (void*) ((u8*) address + offset);
}
char*
arenaCopyCStr(MemoryArena* arena, const char* input, u32 max_len)
{

Loading…
Cancel
Save