ScummVM API documentation
memman.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SWORD1_MEMMAN_H
23 #define SWORD1_MEMMAN_H
24 
25 #include "common/scummsys.h"
26 
27 namespace Sword1 {
28 
29 struct MemHandle {
30  void *data;
31  uint32 size;
32  uint32 refCount;
33  uint16 cond;
34  MemHandle *next, *prev;
35 };
36 // mem conditions:
37 #define MEM_FREED 0
38 #define MEM_CAN_FREE 1
39 #define MEM_DONT_FREE 2
40 
41 #define MAX_ALLOC (6*1024*1024) // max amount of mem we want to alloc().
42 
43 class MemMan {
44 public:
45  MemMan();
46  ~MemMan();
47  void alloc(MemHandle *bsMem, uint32 pSize, uint16 pCond = MEM_DONT_FREE);
48  void setCondition(MemHandle *bsMem, uint16 pCond);
49  void freeNow(MemHandle *bsMem);
50  void initHandle(MemHandle *bsMem);
51  void flush();
52 private:
53  void addToFreeList(MemHandle *bsMem);
54  void removeFromFreeList(MemHandle *bsMem);
55  void checkMemoryUsage();
56  uint32 _alloced; //currently allocated memory
57  MemHandle *_memListFree;
58  MemHandle *_memListFreeEnd;
59 };
60 
61 } // End of namespace Sword1
62 
63 #endif //MEMMAN_H
Definition: memman.h:43
Definition: animation.h:38
Definition: memman.h:29