blob: 0188999997e46cb2ebc777f7df4465a1df7c2f29 (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#if !defined( __TOBJECT_H )
#define __TOBJECT_H
#if !defined( __TTYPES_H )
#include "h_types.h"
#endif
class HSmallAllocator;
struct HRegisteredObject
{
#if !defined( __NO_MEM_MANAGER__ )
void* operator new( size_t sz, HSmallAllocator& A );
void* operator new( size_t sz );
void operator delete( void* ptr );
#endif
};
struct HObject : public HRegisteredObject
{
virtual ~HObject() {}
};
//====[ Пул для ускорения выделений маленьких кусочков памяти ]================
struct HDataPage
{
HDataPage* next;
size_t free;
};
class HSmallAllocator : public HRegisteredObject
{
friend struct HSmallAllocatorObject;
friend struct HSmartSmallAllocatorObject;
protected: size_t pageSize;
HDataPage* first;
void* allocateSpace( size_t );
public:
HSmallAllocator( size_t = 1024 );
~HSmallAllocator();
char* placeStr( const char* );
void* placeData( const void*, size_t );
friend void* operator new( size_t, HSmallAllocator& );
virtual void tide();
};
struct HStaticSmallAllocator : public HSmallAllocator
{
HStaticSmallAllocator( size_t pPageSize );
virtual void tide();
};
struct HSmallAllocatorObject
{
void* operator new( size_t, HSmallAllocator& );
void* operator new[]( size_t, HSmallAllocator& );
inline void operator delete( void* )
{}
inline void operator delete[]( void* )
{}
};
struct HSmartSmallAllocatorObject : public HSmallAllocatorObject
{
void* operator new( size_t, HSmallAllocator& );
void* operator new[]( size_t, HSmallAllocator& );
};
inline HSmallAllocator& ALLOCATOR( void* Obj )
{
void** p = ( void** )Obj;
return *( HSmallAllocator* )p[ -1 ];
}
//====[ Реализация инлайновых методов HRegisteredObject ]======================
#if !defined( __NO_MEM_MANAGER__ )
inline void* HRegisteredObject::operator new( size_t sz, HSmallAllocator& A )
{ return ::operator new( sz, A );
}
inline void* HRegisteredObject::operator new( size_t sz )
{ return HNEW( char, sz );
}
inline void HRegisteredObject::operator delete( void* ptr )
{ ::delete ptr );
}
#endif
#endif
|