ClanLib  2.3.7
block_allocator.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
31 
32 
33 #pragma once
34 
35 
36 #include "../api_core.h"
37 #include "sharedptr.h"
38 #include "system.h"
39 
40 class CL_BlockAllocator_Impl;
41 
54 {
57 
58 public:
61 
62 
66 
67 public:
68 
69 
73 
74 public:
76 
79  void *allocate(int size);
80 
82 
83  void free();
84 
86 
87  template<typename Type>
88  Type *new_obj()
89  {
90  Type *data = (Type *) allocate(sizeof(Type));
91  CL_System::call_constructor<Type>(data);
92  return data;
93  }
94 
96 
98  template<typename Type, typename P1>
99  Type *new_obj(P1 p1)
100  {
101  Type *data = (Type *) allocate(sizeof(Type));
102  CL_System::call_constructor<Type, P1>(data, p1);
103  return data;
104  }
105 
107 
110  template<typename Type, typename P1, typename P2>
111  Type *new_obj(P1 p1, P2 p2)
112  {
113  Type *data = (Type *) allocate(sizeof(Type));
114  CL_System::call_constructor<Type, P1, P2>(data, p1, p2);
115  return data;
116  }
117 
119 
123  template<typename Type, typename P1, typename P2, typename P3>
124  Type *new_obj(P1 p1, P2 p2, P3 p3)
125  {
126  Type *data = (Type *) allocate(sizeof(Type));
127  CL_System::call_constructor<Type, P1, P2, P3>(data, p1, p2, p3);
128  return data;
129  }
130 
132 
137  template<typename Type, typename P1, typename P2, typename P3, typename P4>
138  Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4)
139  {
140  Type *data = (Type *) allocate(sizeof(Type));
141  CL_System::call_constructor<Type, P1, P2, P3, P4>(data, p1, p2, p3, p4);
142  return data;
143  }
144 
146 
152  template<typename Type, typename P1, typename P2, typename P3, typename P4, typename P5>
153  Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
154  {
155  Type *data = (Type *) allocate(sizeof(Type));
156  CL_System::call_constructor<Type, P1, P2, P3, P4, P5>(data, p1, p2, p3, p4, p5);
157  return data;
158  }
159 
161 
168  template<typename Type, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
169  Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
170  {
171  Type *data = (Type *) allocate(sizeof(Type));
172  CL_System::call_constructor<Type, P1, P2, P3, P4, P5, P6>(data, p1, p2, p3, p4, p5, p6);
173  return data;
174  }
175 
177 
185  template<typename Type, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
186  Type *new_obj(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
187  {
188  Type *data = (Type *) allocate(sizeof(Type));
189  CL_System::call_constructor<Type, P1, P2, P3, P4, P5, P6, P7>(data, p1, p2, p3, p4, p5, p6, p7);
190  return data;
191  }
192 
194 
196  template<typename Type>
197  void delete_obj(Type *obj)
198  {
200  }
201 
202 
206 
207 private:
208  CL_SharedPtr<CL_BlockAllocator_Impl> impl;
210 };
211 
225 {
228 
229 public:
230  void *operator new(size_t size, CL_BlockAllocator *allocator);
231 
232  void operator delete(void *data, size_t size);
233 
234  void operator delete(void *data, CL_BlockAllocator *allocator);
236 };
237 
238 
239