changed copyright years in source files
[fegdk.git] / core / code / system / mmanager.h
blobe37e94087278edef3face2153ce86abd20255117
1 /*
2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Alexander Maltsev
20 keltar@users.sourceforge.net
23 #ifndef __F_MMANAGER_H
24 #define __F_MMANAGER_H
26 #include "f_types.h"
27 #include "f_baseobject.h"
28 #include "f_engine.h"
30 namespace fe
33 class pool : public baseObject
35 public:
36 explicit pool (uint32 elem_size, uint32 num_elems);
37 ~pool ();
39 void *alloc ();
40 void free (void *p);
42 protected:
43 uint32 mElemSize;
44 uint32 mNumElems;
45 uint32 *mpLastAllocated;
46 ubyte mLastBit;
47 uint32 mNumBitfields;
48 ubyte *mpMemory;
49 uint32 *mpBitfields;
52 class stackAllocator : public baseObject
54 public:
55 explicit stackAllocator (uint32 size);
56 ~stackAllocator ();
58 uint32 getMark () const;
59 void setMark (uint32 mark);
61 void *alloc (uint32 size);
63 protected:
64 ubyte *mpPtr;
65 uint32 mSize;
66 uint32 mMark;
69 class stackAllocatorHandle
71 public:
72 stackAllocatorHandle () : mpAllocator (g_engine->getStackAllocator ())
74 mMark = mpAllocator->getMark ();
76 stackAllocatorHandle (stackAllocator &a) : mpAllocator (&a)
78 mMark = a.getMark ();
80 ~stackAllocatorHandle ()
82 mpAllocator->setMark (mMark);
85 void *alloc (uint32 size)
87 return mpAllocator->alloc (size);
90 protected:
91 uint32 mMark;
92 stackAllocator *mpAllocator;
96 uint32 getUsedMemorySize ();
100 #endif