acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
plex_heap_alloc.h
1
#pragma once
2
3
4
#include "plex_heap_alloc_sync.h"
5
6
7
class
CLASS_DECL_ACME plex_heap_alloc :
8
public
::array_base < plex_heap_alloc_sync *, plex_heap_alloc_sync * >
9
{
10
protected
:
11
12
13
friend
class ::allocator::accessor;
14
friend
class
plex_heap_alloc_array;
15
16
17
plex_heap_alloc(
::heap::allocator
* pallocator, memsize nAllocSize, ::u32 nBlockSize = 64);
18
virtual
~plex_heap_alloc();
19
20
21
public
:
22
23
// // Now alloc from any pool and release to any pool (not necessaraly the same allocated at) . save four bytes per allocation
24
::heap::allocator
* m_pallocator;
25
::i32 m_iAlloc;
// Now alloc from any pool
26
::i32 m_iFree;
// and release to any pool
27
::i32 m_iShareCount;
28
::i32 m_iShareBound;
29
::i32 m_iAllocSize;
30
31
32
33
inline ::u32 GetAllocSize() {
return
m_iAllocSize; }
34
35
void
* Alloc();
// return a chunk of memory of nAllocSize
36
void
Free(
void
* p);
// free chunk of memory returned from Alloc
37
void
FreeAll();
// free everything allocated from this allocator
38
39
void
NewBlock();
40
41
void
pre_finalize();
42
43
//void * operator new(size_t s);
44
//void operator delete(void * p);
45
46
47
//plex_heap_alloc_sync * new_plex_heap_alloc_sync(memsize nAllocSize, ::u32 nBlockSize = 64);
48
//void delete_plex_heap_alloc_sync(plex_heap_alloc_sync *p);
49
50
51
52
};
53
54
55
inline
void
* plex_heap_alloc::Alloc()
56
{
57
58
// veripseudo-random generator, don't need to be
59
// perfectly sequential or perfectly distributed,
60
// just fair well distributed
61
// but very important is extremely fast
62
63
auto
iAlloc = m_iAlloc;
64
65
m_iAlloc = (iAlloc + 1) % m_iShareCount;
66
67
iAlloc %= m_iShareCount;
68
69
return
element_at(iAlloc)->Alloc();
70
71
}
72
73
inline
void
plex_heap_alloc::Free(
void
* p)
74
{
75
76
// veripseudo-random generator, don't need to be
77
// perfectly sequential or perfectly distributed,
78
// just fair well distributed
79
// but very important is extremely fast
80
81
element_at((m_iFree++) % m_iShareCount)->Free(p);
82
83
}
84
85
86
87
88
//#define PLEX_HEAP_ALLOC_ARRAY_AINDEX_COUNT 3
89
90
//#ifdef OS64BIT
91
//#define PLEX_HEAP_ALLOC_ARRAY_BINDEX_COUNT 6
92
//#else
93
//#define PLEX_HEAP_ALLOC_ARRAY_BINDEX_COUNT 5
94
//#endif
heap::allocator
Definition
allocator.h:37
memory
plex_heap_alloc.h
Generated by
1.17.0