2003-12-16 02:10:15 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2003-2006 The ScummVM project
|
2003-12-16 02:10:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-12-16 02:10:15 +00:00
|
|
|
*
|
2006-02-11 10:01:01 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-12-16 02:10:15 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MEMMAN_H
|
|
|
|
#define MEMMAN_H
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/scummsys.h"
|
2003-12-16 02:10:15 +00:00
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
namespace Sword1 {
|
|
|
|
|
|
|
|
struct MemHandle {
|
2003-12-16 02:10:15 +00:00
|
|
|
void *data;
|
|
|
|
uint32 size;
|
|
|
|
uint32 refCount;
|
|
|
|
uint16 cond;
|
2004-01-11 15:47:41 +00:00
|
|
|
MemHandle *next, *prev;
|
2003-12-16 02:10:15 +00:00
|
|
|
};
|
|
|
|
// mem conditions:
|
|
|
|
#define MEM_FREED 0
|
|
|
|
#define MEM_CAN_FREE 1
|
|
|
|
#define MEM_DONT_FREE 2
|
|
|
|
|
|
|
|
#define MAX_ALLOC (6*1024*1024) // max amount of mem we want to alloc().
|
|
|
|
|
|
|
|
class MemMan {
|
|
|
|
public:
|
|
|
|
MemMan(void);
|
|
|
|
~MemMan(void);
|
2004-01-11 15:47:41 +00:00
|
|
|
void alloc(MemHandle *bsMem, uint32 pSize, uint16 pCond = MEM_DONT_FREE);
|
|
|
|
void setCondition(MemHandle *bsMem, uint16 pCond);
|
|
|
|
void freeNow(MemHandle *bsMem);
|
|
|
|
void initHandle(MemHandle *bsMem);
|
2003-12-20 09:12:54 +00:00
|
|
|
void flush(void);
|
2003-12-16 02:10:15 +00:00
|
|
|
private:
|
2004-01-11 15:47:41 +00:00
|
|
|
void addToFreeList(MemHandle *bsMem);
|
|
|
|
void removeFromFreeList(MemHandle *bsMem);
|
2003-12-16 02:10:15 +00:00
|
|
|
void checkMemoryUsage(void);
|
|
|
|
uint32 _alloced; //currently allocated memory
|
2004-01-11 15:47:41 +00:00
|
|
|
MemHandle *_memListFree;
|
|
|
|
MemHandle *_memListFreeEnd;
|
2003-12-16 02:10:15 +00:00
|
|
|
};
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
} // End of namespace Sword1
|
2004-01-11 15:47:41 +00:00
|
|
|
|
2003-12-16 02:10:15 +00:00
|
|
|
#endif //MEMMAN_H
|