13 #ifndef HERMES_MEMORY_MANAGEMENT_H_
14 #define HERMES_MEMORY_MANAGEMENT_H_
229 void InitArena(Arena *arena,
size_t bytes,
u8 *base);
272 void GrowArena(Arena *arena,
size_t new_size);
286 u8 *
PushSize(Arena *arena,
size_t size,
size_t alignment = 8);
312 template <
typename T>
314 T *result =
reinterpret_cast<T *
>(
PushSize(arena,
sizeof(T), alignment));
330 template <
typename T>
350 template <
typename T>
353 reinterpret_cast<T *
>(
PushSize(arena,
sizeof(T) * count, alignment));
368 template <
typename T>
370 T *result =
reinterpret_cast<T *
>(
380 template <
typename T>
382 T *result =
reinterpret_cast<T *
>(
HeapPushSize(heap,
sizeof(T)));
390 template <
typename T>
392 T *result =
reinterpret_cast<T *
>(
HeapPushSize(heap, count *
sizeof(T)));
398 void HeapFree(Heap *heap,
void *ptr);
399 void *
HeapRealloc(Heap *heap,
void *ptr,
size_t size);
#define HERMES_NOT_IMPLEMENTED_YET
Definition: hermes_types.h:191
Definition: adapter_utils.cc:35
T * PushClearedStruct(Arena *arena, size_t alignment=8)
Definition: memory_management.h:331
void EndWriterLock(RwLock *lock)
Definition: memory_management.cc:618
size_t GetRemainingCapacity(Arena *arena)
Definition: memory_management.cc:103
bool BeginReaderLock(RwLock *lock)
Definition: memory_management.cc:567
FreeBlock * NextFreeBlock(Heap *heap, FreeBlock *block)
Definition: memory_management.cc:211
u8 * HeapOffsetToPtr(Heap *heap, u32 offset)
Definition: memory_management.cc:228
Heap * InitHeapInArena(Arena *arena, bool grows_up, u16 alignment)
Definition: memory_management.cc:290
void BeginWriterLock(RwLock *lock)
Definition: memory_management.cc:601
uint16_t u16
Definition: hermes_types.h:41
u8 * PushSizeAndClear(Arena *arena, size_t size, size_t alignment)
Definition: memory_management.cc:170
void HeapFree(Heap *heap, void *ptr)
Definition: memory_management.cc:460
T * PushArray(Arena *arena, int count, size_t alignment=8)
Definition: memory_management.h:351
void EndReaderLock(RwLock *lock)
Definition: memory_management.cc:580
TemporaryMemory BeginTemporaryMemory(Arena *arena)
Definition: memory_management.cc:128
void EndTicketMutex(TicketMutex *mutex)
Definition: memory_management.cc:557
T * HeapPushStruct(Heap *heap)
Definition: memory_management.h:381
@ kArenaType_Count
Definition: hermes_types.h:244
uint8_t u8
Definition: hermes_types.h:40
u32 GetHeapOffset(Heap *heap, u8 *ptr)
Definition: memory_management.cc:242
void() ArenaErrorFunc()
Definition: memory_management.h:30
void BeginTicketMutex(TicketMutex *mutex)
Definition: memory_management.cc:539
void EndTemporaryMemory(TemporaryMemory *temp_memory)
Definition: memory_management.cc:139
u8 * HeapExtentToPtr(Heap *heap)
Definition: memory_management.cc:274
void GrowArena(Arena *arena, size_t new_size)
The maximum capacity of arena becomes new_size.
Definition: memory_management.cc:112
u8 * PushSize(Arena *arena, size_t size, size_t alignment)
Definition: memory_management.cc:145
uint32_t u32
Definition: hermes_types.h:42
T * PushStruct(Arena *arena, size_t alignment=8)
Definition: memory_management.h:313
void DestroyArena(Arena *arena)
Definition: memory_management.cc:92
int32_t i32
Definition: hermes_types.h:46
FreeBlock * GetHeapFreeList(Heap *heap)
Definition: memory_management.cc:195
Arena InitArenaAndAllocate(size_t bytes)
Definition: memory_management.cc:81
void * HeapRealloc(Heap *heap, void *ptr, size_t size)
Definition: memory_management.cc:493
T * HeapPushArray(Heap *heap, u32 count)
Definition: memory_management.h:391
void InitArena(Arena *arena, size_t bytes, u8 *base)
Definition: memory_management.cc:71
T * PushClearedArray(Arena *arena, int count, size_t alignment=8)
Definition: memory_management.h:369
u8 * HeapPushSize(Heap *heap, u32 size)
Definition: memory_management.cc:414
Definition: memory_management.h:84
i32 temp_count
Definition: memory_management.h:94
ArenaErrorFunc * error_handler
Definition: memory_management.h:92
size_t capacity
Definition: memory_management.h:90
size_t used
Definition: memory_management.h:88
u8 * base
Definition: memory_management.h:86
Definition: memory_management.h:62
size_t sizes[kArenaType_Count]
Definition: memory_management.h:63
size_t total
Definition: memory_management.h:64
Definition: memory_management.h:131
u32 size
Definition: memory_management.h:135
u32 next_offset
Definition: memory_management.h:133
Definition: memory_management.h:100
bool grows_up
Definition: memory_management.h:118
ArenaErrorFunc * error_handler
Definition: memory_management.h:102
u32 base_offset
Definition: memory_management.h:106
TicketMutex mutex
Definition: memory_management.h:104
u32 free_list_offset
Definition: memory_management.h:108
u32 extent
Definition: memory_management.h:113
u16 alignment
Definition: memory_management.h:116
Definition: memory_management.h:53
std::atomic< bool > writer_waiting
Definition: memory_management.h:56
TicketMutex mutex
Definition: memory_management.h:54
std::atomic< u32 > readers
Definition: memory_management.h:55
Definition: memory_management.h:168
Arena * arena
Definition: memory_management.h:170
ScopedTemporaryMemory(Arena *backing_arena)
Definition: memory_management.h:183
size_t used
Definition: memory_management.h:172
~ScopedTemporaryMemory()
Definition: memory_management.h:196
Definition: memory_management.h:141
size_t used
Definition: memory_management.h:143
Arena * arena
Definition: memory_management.h:142
Definition: memory_management.h:44
Ticket()
Definition: memory_management.h:47
bool acquired
Definition: memory_management.h:46
u32 ticket
Definition: memory_management.h:45
Definition: memory_management.h:36
std::atomic< u32 > serving
Definition: memory_management.h:38
std::atomic< u32 > ticket
Definition: memory_management.h:37