vn/code/core/core_memory.h

59 lines
1.8 KiB
C
Raw Normal View History

2023-06-21 16:59:36 +00:00
/* date = June 19th 2023 10:07 pm */
#ifndef CORE_MEMORY_H
#define CORE_MEMORY_H
2023-07-19 15:09:41 +00:00
////////////////////////////////
//- sixten: Common Memory Functions
2023-06-21 16:59:36 +00:00
static void Copy(void *Dest, void *Source, umm Count);
2023-07-19 15:09:41 +00:00
static void CopyReverse(void *Dest, void *Source, umm Count);
2023-06-21 16:59:36 +00:00
static void Fill(void *Dest, u8 Value, umm Count);
2023-07-19 15:09:41 +00:00
#define Move(Dest, Source, Count) memmove(Dest, Source, Count)
2023-06-21 16:59:36 +00:00
2023-07-19 15:09:41 +00:00
////////////////////////////////
//- sixten: Memory Arena Types
2023-06-21 16:59:36 +00:00
struct memory_arena
{
2023-07-19 15:09:41 +00:00
u64 Position;
u64 CommitPosition;
u64 Size;
u64 Align;
u64 Unused[4];
2023-06-21 16:59:36 +00:00
};
struct temporary_memory
{
memory_arena *Arena;
2023-07-19 15:09:41 +00:00
u64 Position;
2023-06-21 16:59:36 +00:00
};
2023-07-19 15:09:41 +00:00
////////////////////////////////
//~ sixten: Memory Arena Settings
#define MEMORY_ARENA_COMMIT_SIZE Kilobytes(4)
#define MEMORY_ARENA_DECOMMIT_THRESHOLD Megabytes(64)
////////////////////////////////
//- sixten: Memory Arena Functions
static memory_arena *ArenaAllocate(u64 Size);
static void ArenaRelease(memory_arena *Arena);
static void *ArenaPushNoClear(memory_arena *Arena, u64 Size);
static void *ArenaPush(memory_arena *Arena, u64 Size);
static void ArenaPopTo(memory_arena *Arena, u64 Position);
static void ArenaClear(memory_arena *Arena);
static void ArenaSetAlign(memory_arena *Arena, u64 Align);
#define PushArray(Arena, type, Count) (type *)ArenaPush((Arena), sizeof(type)*(Count))
#define PushArrayNoClear(Arena, type, Count) (type *)ArenaPushNoClear((Arena), sizeof(type)*(Count))
#define PushStruct(Arena, type) (type *)ArenaPush((Arena), sizeof(type))
#define PushStructNoClear(Arena, type) (type *)ArenaPushNoClear((Arena), sizeof(type))
////////////////////////////////
//- sixten: Temporary Memory Functions
2023-06-21 16:59:36 +00:00
static temporary_memory BeginTemporaryMemory(memory_arena *Arena);
static void EndTemporaryMemory(temporary_memory Temp);
#endif //CORE_MEMORY_H