acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
plex_heap_alloc_sync.h
1#pragma once
2
3
4class plex_heap;
5
6
7class CLASS_DECL_ACME plex_heap_alloc_sync
8{
9protected:
10
11
12 friend class ::allocator::accessor;
13 friend class plex_heap_alloc;
14
15
16 plex_heap_alloc_sync(::heap::allocator * pallocator, memsize nAllocSize, ::u32 nBlockSize = 64);
17 virtual ~plex_heap_alloc_sync();
18
19
20public:
21
22
23 struct node
24 {
25
26 node * m_pnext; // only valid when in free list_base
27
28 };
29
30
31 ::heap::allocator * m_pallocator;
32 ::i32 m_nAllocSize; // i32_size of each block from Alloc
33 ::i32 m_nBlockSize; // number of blocks to get at a time
34 plex_heap * m_pBlocks; // linked list_base of blocks (is nBlocks*nAllocSize)
35 node* m_pnodeFree; // first free node (nullptr if no free nodes)
36 ::critical_section m_criticalsection;
37 ::i64 m_iFreeHitCount;
38 node * m_pnodeLastBlock;
39
40
41
42 ::u32 GetAllocSize() { return m_nAllocSize; }
43
44 void * Alloc(); // return a chunk of memory of nAllocSize
45 void Free(void * p); // free chunk of memory returned from Alloc
46 void FreeAll(); // free everything allocated from this allocator
47
48 void NewBlock();
49
50
51};
52
53
Definition critical_section.h:9
Definition allocator.h:37
Definition plex_heap.h:7
Definition plex_heap_alloc_sync.h:24