77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
|
/* date = June 19th 2023 10:07 pm */
|
||
|
|
||
|
#ifndef CORE_MEMORY_H
|
||
|
#define CORE_MEMORY_H
|
||
|
|
||
|
//- sixten: Common memory functions
|
||
|
|
||
|
static void Copy(void *Dest, void *Source, umm Count);
|
||
|
static void Fill(void *Dest, u8 Value, umm Count);
|
||
|
|
||
|
//- sixten: Memory arena types
|
||
|
|
||
|
struct platform_memory_block;
|
||
|
|
||
|
struct memory_arena
|
||
|
{
|
||
|
platform_memory_block *CurrentBlock;
|
||
|
umm MinimumBlockSize;
|
||
|
s32 TemporaryMemoryCount;
|
||
|
};
|
||
|
|
||
|
struct temporary_memory
|
||
|
{
|
||
|
memory_arena *Arena;
|
||
|
platform_memory_block *Block;
|
||
|
umm Used;
|
||
|
};
|
||
|
|
||
|
//- sixten: Arena push flags
|
||
|
|
||
|
enum arena_push_flag
|
||
|
{
|
||
|
ArenaFlag_ClearToZero = 0x1,
|
||
|
};
|
||
|
|
||
|
struct arena_push_params
|
||
|
{
|
||
|
u32 Flags;
|
||
|
u32 Alignment;
|
||
|
};
|
||
|
|
||
|
inline arena_push_params DefaultArenaParams(void)
|
||
|
{
|
||
|
arena_push_params Params = {};
|
||
|
Params.Flags = ArenaFlag_ClearToZero;
|
||
|
Params.Alignment = 4;
|
||
|
return(Params);
|
||
|
}
|
||
|
|
||
|
inline arena_push_params NoClear(void)
|
||
|
{
|
||
|
arena_push_params Params = DefaultArenaParams();
|
||
|
Params.Flags &= ~ArenaFlag_ClearToZero;
|
||
|
return(Params);
|
||
|
}
|
||
|
|
||
|
//- sixten: Memory arena functions
|
||
|
|
||
|
static void Release(memory_arena *Arena);
|
||
|
|
||
|
#define PushSize(Arena, InitialSize, ...) PushSize_(Arena, InitialSize, __VA_ARGS__)
|
||
|
#define PushStruct(Arena, type, ...) (type *)PushSize_(Arena, sizeof(type), __VA_ARGS__)
|
||
|
#define PushArray(Arena, type, Count, ...) (type *)PushSize_(Arena, sizeof(type)*Count, __VA_ARGS__)
|
||
|
static void *PushSize_(memory_arena *Arena, umm InitialSize, arena_push_params Params = DefaultArenaParams());
|
||
|
|
||
|
//- sixten: Bootstrapping helpers
|
||
|
|
||
|
#define BootstrapPushStruct(type, Member) (type *)BootstrapPushSize(sizeof(type), OffsetOf(type, Member))
|
||
|
static void *BootstrapPushSize(umm Size, umm OffsetToArena);
|
||
|
|
||
|
//- sixten: Temporary memory functions
|
||
|
|
||
|
static temporary_memory BeginTemporaryMemory(memory_arena *Arena);
|
||
|
static void EndTemporaryMemory(temporary_memory Temp);
|
||
|
|
||
|
#endif //CORE_MEMORY_H
|