Dali 3D User Interface Engine
memory-pool-object-allocator.h
Go to the documentation of this file.
1 #ifndef __DALI_INTERNAL_MEMORY_POOL_OBJECT_ALLOCATOR_H__
2 #define __DALI_INTERNAL_MEMORY_POOL_OBJECT_ALLOCATOR_H__
3 
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20 
21 // INTERNAL INCLUDES
23 
24 namespace Dali
25 {
26 
27 namespace Internal
28 {
29 
37 template< typename T >
39 {
40 public:
41 
46  : mPool( NULL )
47  {
49  }
50 
55  {
56  delete mPool;
57  }
58 
64  T* Allocate()
65  {
66  return new ( mPool->Allocate() ) T();
67  }
68 
75  {
76  return new ( mPool->AllocateThreadSafe() ) T();
77  }
78 
87  void* AllocateRaw()
88  {
89  return mPool->Allocate();
90  }
91 
98  {
99  return mPool->AllocateThreadSafe();
100  }
101 
107  void Free( T* object )
108  {
109  object->~T();
110 
111  mPool->Free( object );
112  }
113 
119  void FreeThreadSafe( T* object )
120  {
121  object->~T();
122 
123  mPool->FreeThreadSafe( object );
124  }
125 
130  {
131  if( mPool )
132  {
133  delete mPool;
134  }
135 
137  }
138 
139 private:
140 
141  // Undefined
142  MemoryPoolObjectAllocator( const MemoryPoolObjectAllocator& memoryPoolObjectAllocator );
143 
144  // Undefined
145  MemoryPoolObjectAllocator& operator=( const MemoryPoolObjectAllocator& memoryPoolObjectAllocator );
146 
147 private:
148 
150 
151 };
152 
153 } // namespace Internal
154 
155 } // namespace Dali
156 
157 #endif /* __DALI_INTERNAL_MEMORY_POOL_OBJECT_ALLOCATOR_H__ */
Dali Docs Home
Read more about Dali