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 * Additional copyright for this file: 8 * Copyright (C) 1994-1998 Revolution Software Ltd. 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version 2 13 * of the License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 */ 24 25 #ifndef SWORD2_MEMORY_H 26 #define SWORD2_MEMORY_H 27 28 enum { 29 MAX_MEMORY_BLOCKS = 999 30 }; 31 32 namespace Sword2 { 33 34 struct MemBlock { 35 int16 id; 36 int16 uid; 37 byte *ptr; 38 uint32 size; 39 }; 40 41 class MemoryManager { 42 private: 43 MemBlock *_memBlocks; 44 MemBlock **_memBlockIndex; 45 int16 _numBlocks; 46 47 uint32 _totAlloc; 48 49 int16 *_idStack; 50 int16 _idStackPtr; 51 52 int16 findExactPointerInIndex(byte *ptr); 53 int16 findPointerInIndex(byte *ptr); 54 int16 findInsertionPointInIndex(byte *ptr); 55 56 public: 57 MemoryManager(); 58 ~MemoryManager(); 59 getNumBlocks()60 int16 getNumBlocks() { return _numBlocks; } getTotAlloc()61 uint32 getTotAlloc() { return _totAlloc; } getMemBlocks()62 MemBlock *getMemBlocks() { return _memBlocks; } 63 64 int32 encodePtr(byte *ptr); 65 byte *decodePtr(int32 n); 66 67 byte *memAlloc(uint32 size, int16 uid); 68 void memFree(byte *ptr); 69 }; 70 71 } // End of namespace Sword2 72 73 #endif 74