~vladh/peony

peony/src/memory.hpp -rw-r--r-- 839 bytes
7fc9922bVlad-Stefan Harbuz changes shaders namespace into class a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

#pragma once

#include "types.hpp"

#define MEMORY_PUSH(pool, type, debug_name) \
  (type*)memory::push(pool, sizeof(type), debug_name)

namespace memory {
  #if USE_MEMORYPOOL_ITEM_DEBUG
    constexpr uint32 MAX_N_MEMORYPOOL_ITEMS = 1024;
  #endif

  struct MemoryPool {
    uint8 *memory;
    size_t size;
    size_t used;
    uint32 n_items;
    #if USE_MEMORYPOOL_ITEM_DEBUG
      const char *item_debug_names[MAX_N_MEMORYPOOL_ITEMS];
      size_t item_debug_sizes[MAX_N_MEMORYPOOL_ITEMS];
    #endif
  };

  void* push(
    MemoryPool *pool,
    size_t item_size,
    const char *item_debug_name
  );
  void print_memory_pool(MemoryPool *pool);
  void destroy_memory_pool(MemoryPool *memory_pool);
}

using memory::MemoryPool;