Dali 3D User Interface Engine
utc-Dali-Internal-FixedSizeMemoryPool.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
19 #include <dali-test-suite-utils.h>
20 
21 // Internal headers are allowed here
22 
24 
25 using namespace Dali;
26 
28 {
30 }
31 
33 {
35 }
36 
37 namespace
38 {
39 
40 unsigned int gTestObjectConstructed = 0;
41 unsigned int gTestObjectDestructed = 0;
42 unsigned int gTestObjectMethod = 0;
43 unsigned int gTestObjectDataAccess = 0;
44 
45 } // namespace
46 
47 
49 {
50 public:
51 
53  : mData1( 0 ),
54  mData2( false )
55  {
57  }
58 
60  {
62  }
63 
64  void Method()
65  {
67  }
68 
69  void DataAccess()
70  {
71  mData1++;
72  mData2 = true;
73 
75  }
76 
77 private:
78 
79  unsigned int mData1;
80  bool mData2;
81 
82 };
83 
85 {
90 
91  Internal::FixedSizeMemoryPool memoryPool( Internal::TypeSizeWithAlignment< TestObject >::size );
92 
93  TestObject* testObject1 = new (memoryPool.Allocate()) TestObject();
94  DALI_TEST_CHECK( testObject1 );
96 
97  testObject1->Method();
99 
100  testObject1->DataAccess();
102 
103  testObject1->~TestObject();
104  memoryPool.Free( testObject1 );
106 
107  END_TEST;
108 }
109 
111 {
114  gTestObjectMethod = 0;
116 
117  const size_t initialCapacity = 32;
118  const size_t maximumCapacity = 1024;
119 
120  const unsigned int numObjects = 1024 * 1024;
121 
122  Internal::FixedSizeMemoryPool memoryPool( Internal::TypeSizeWithAlignment< TestObject >::size, initialCapacity, maximumCapacity );
123 
125  objects.Reserve( numObjects );
126 
127  for( unsigned int i = 0; i < numObjects; ++i )
128  {
129  TestObject* testObject = new ( memoryPool.Allocate() ) TestObject();
130  DALI_TEST_CHECK( testObject );
131 
132  objects.PushBack( testObject );
133  }
134 
136 
137  for( unsigned int i = 0; i < numObjects; ++i )
138  {
139  objects[i]->~TestObject();
140  memoryPool.Free( objects[i] );
141  }
142 
144 
145  END_TEST;
146 }
Dali Docs Home
Read more about Dali