Orxonox  0.0.5 Codename: Arcturus
SmallObjectAllocator.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Fabian 'x3n' Landau
24  * Co-authors:
25  * ...
26  *
27  */
28 
74 #ifndef _SmallObjectAllocator_H__
75 #define _SmallObjectAllocator_H__
76 
77 #include "UtilPrereqs.h"
78 #include <vector>
79 #include <cstdio>
80 
81 namespace orxonox
82 {
91  {
93  struct Chunk
94  {
96  };
97 
98  public:
99  SmallObjectAllocator(size_t objectSize, size_t numObjects = 64);
101 
102  void* alloc();
103  void free(void* chunk);
104 
105  private:
106  static void setNext(void* chunk, void* next);
107  static void* getNext(void* chunk);
108 
109  void* first_;
110  size_t chunkSize_;
112 
113  std::vector<char*> blocks_;
114  };
115 }
116 
117 #endif /* _SmallObjectAllocator_H__ */
#define _UtilExport
Definition: UtilPrereqs.h:60
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Shared library macros, enums, constants and forward declarations for the util library ...
void * first_
A pointer to the first free memory chunk.
Definition: SmallObjectAllocator.h:109
size_t numChunksPerBlock_
The number of chunks per memory block.
Definition: SmallObjectAllocator.h:111
The memory chunk is at the same time an element of a single linked list.
Definition: SmallObjectAllocator.h:93
This class is used to allocate and free small objects (usually not polymorphic).
Definition: SmallObjectAllocator.h:90
Chunk * next_
A pointer to the next chunk in the list.
Definition: SmallObjectAllocator.h:95
size_t chunkSize_
The size of each chunk (and usually also the size of the created objects)
Definition: SmallObjectAllocator.h:110
std::vector< char * > blocks_
A list of all allocated memory blocks (used to destroy them again)
Definition: SmallObjectAllocator.h:113