a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

memory.h (1016B)


      1 struct StackAllocator
      2 {
      3     u8 *base;
      4     size_t size;
      5     size_t used;
      6 };
      7 
      8 #define KIBIBYTES(n) (n) * 1024LL
      9 #define MEBIBYTES(n) KIBIBYTES((n) * 1024LL)
     10 
     11 #define mem_st_alloc_struct(allocator, type) mem_st_alloc((allocator), sizeof(type), alignof(type))
     12 #define mem_st_alloc_buffer(allocator, type, count) mem_st_alloc((allocator), sizeof(type) * (count), alignof(type))
     13 #define mem_move_buffer(d, s, t, c) mem_move((d), (s), sizeof(t) * (c))
     14 
     15 internal uintptr_t mem_align_address(uintptr_t address, size_t alignment);
     16 internal void mem_st_init(struct StackAllocator *allocator, void *backing_buffer, size_t backing_buffer_bytes);
     17 internal void *mem_st_alloc(struct StackAllocator *allocator, size_t bytes, size_t alignment);
     18 internal size_t mem_st_get_marker(struct StackAllocator *allocator);
     19 internal void mem_st_free_to_marker(struct StackAllocator *allocator, size_t marker);
     20 internal void mem_st_free_all(struct StackAllocator *allocator);
     21 internal void mem_move(void *dest, void *source, size_t num_bytes);