00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00031
00032
00033 #pragma once
00034
00035
00036 #include "../api_core.h"
00037 #include "sharedptr.h"
00038 #include "system.h"
00039
00040 class CL_BlockAllocator_Impl;
00041
00053 class CL_API_CORE CL_BlockAllocator
00054 {
00057
00058 public:
00060 CL_BlockAllocator();
00061
00062
00066
00067 public:
00068
00069
00073
00074 public:
00076
00079 void *allocate(int size);
00080
00082
00083 void free();
00084
00086
00087 template<typename Type>
00088 Type *new_obj()
00089 {
00090 Type *data = (Type *) allocate(sizeof(Type));
00091 CL_System::call_constructor<Type>(data);
00092 return data;
00093 }
00094
00096
00098 template<typename Type, typename P1>
00099 Type *new_obj(P1 p1)
00100 {
00101 Type *data = (Type *) allocate(sizeof(Type));
00102 CL_System::call_constructor<Type, P1>(data, p1);
00103 return data;
00104 }
00105
00107
00110 template<typename Type, typename P1, typename P2>
00111 Type *new_obj(P1 p1, P2 p2)
00112 {
00113 Type *data = (Type *) allocate(sizeof(Type));
00114 CL_System::call_constructor<Type, P1, P2>(data, p1, p2);
00115 return data;
00116 }
00117
00119
00123 template<typename Type, typename P1, typename P2, typename P3>
00124 Type *new_obj(P1 p1, P2 p2, P3 p3)
00125 {
00126 Type *data = (Type *) allocate(sizeof(Type));
00127 CL_System::call_constructor<Type, P1, P2, P3>(data, p1, p2, p3);
00128 return data;
00129 }
00130
00132
00137 template<typename Type, typename P1, typename P2, typename P3, typename P4>
00138 Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4)
00139 {
00140 Type *data = (Type *) allocate(sizeof(Type));
00141 CL_System::call_constructor<Type, P1, P2, P3, P4>(data, p1, p2, p3, p4);
00142 return data;
00143 }
00144
00146
00152 template<typename Type, typename P1, typename P2, typename P3, typename P4, typename P5>
00153 Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
00154 {
00155 Type *data = (Type *) allocate(sizeof(Type));
00156 CL_System::call_constructor<Type, P1, P2, P3, P4, P5>(data, p1, p2, p3, p4, p5);
00157 return data;
00158 }
00159
00161
00168 template<typename Type, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00169 Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
00170 {
00171 Type *data = (Type *) allocate(sizeof(Type));
00172 CL_System::call_constructor<Type, P1, P2, P3, P4, P5, P6>(data, p1, p2, p3, p4, p5, p6);
00173 return data;
00174 }
00175
00177
00185 template<typename Type, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
00186 Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
00187 {
00188 Type *data = (Type *) allocate(sizeof(Type));
00189 CL_System::call_constructor<Type, P1, P2, P3, P4, P5, P6, P7>(data, p1, p2, p3, p4, p5, p6, p7);
00190 return data;
00191 }
00192
00194
00196 template<typename Type>
00197 void delete_obj(Type *obj)
00198 {
00199 CL_System::call_destructor(obj);
00200 }
00201
00202
00206
00207 private:
00208 CL_SharedPtr<CL_BlockAllocator_Impl> impl;
00210 };
00211
00224 class CL_BlockAllocated
00225 {
00228
00229 public:
00230 void *operator new(size_t size, CL_BlockAllocator *allocator);
00231
00232 void operator delete(void *data, size_t size);
00233
00234 void operator delete(void *data, CL_BlockAllocator *allocator);
00236 };
00237
00238
00239