ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
memory-manager.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 ELF_MEMORY_MANAGER_H
23 #define ELF_MEMORY_MANAGER_H
24 
25 #include "common/scummsys.h"
26 
27 #if defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER)
28 
29 #include "common/singleton.h"
30 #include "common/list.h"
31 #include "common/mutex.h"
32 
39 #define ELFMemMan ELFMemoryManager::instance()
40 
41 class ELFMemoryManager : public Common::Singleton<ELFMemoryManager> {
42 public:
43  void trackPlugin(bool value);
44  void trackAlloc(uint32 align, uint32 size);
45 
46  void allocateHeap();
47 
48  void *pluginAllocate(uint32 size);
49  void *pluginAllocate(uint32 align, uint32 size);
50  void pluginDeallocate(void *ptr);
51 
52 private:
53  friend class Common::Singleton<ELFMemoryManager>;
54 
55  ELFMemoryManager();
56  ~ELFMemoryManager();
57 
58  void *allocateOnHeap(uint32 align, uint32 size);
59  void deallocateFromHeap(void *ptr);
60 
61  struct Allocation {
62  byte *start;
63  uint32 size;
64  byte *end() { return start + size; }
65  Allocation(byte *a, uint32 b) : start(a), size(b) {}
66  };
67 
68  // heap
69  void *_heap;
70  uint32 _heapAlign; // alignment of the heap
71  uint32 _heapSize; // size of the heap
72 
73  // tracking allocations
74  bool _trackAllocs; // whether we are currently tracking
75  uint32 _measuredSize;
76  uint32 _measuredAlign;
77 
78  // real allocations
79  Common::List<Allocation> _allocList;
80  uint32 _bytesAllocated;
81 };
82 
83 #endif /* defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) */
84 
85 #endif /* ELF_MEMORY_MANAGER_H */
Definition: singleton.h:42