2009-02-17 15:02:16 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
#ifndef _SCI_HEAP_H
|
|
|
|
#define _SCI_HEAP_H
|
|
|
|
|
2009-02-21 18:28:38 +00:00
|
|
|
#include "sci/tools.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
#define SCI_HEAP_SIZE 0x10000
|
|
|
|
|
|
|
|
typedef guint16 heap_ptr;
|
|
|
|
|
2009-02-15 22:28:12 +00:00
|
|
|
typedef struct {
|
2009-02-19 18:08:44 +00:00
|
|
|
byte *start;
|
|
|
|
byte *base;
|
2009-02-15 06:10:59 +00:00
|
|
|
unsigned int first_free;
|
|
|
|
int old_ff;
|
|
|
|
} heap_t;
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
heap_t *heap_new();
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Allocates a new heap.
|
|
|
|
** Parameters: (void)
|
|
|
|
** Returns : (heap_t *) A new 0xffff-sized heap
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
void heap_del(heap_t *h);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Frees an allocated heap
|
|
|
|
** Parameters: (heap_t *) h: The heap to unallocate
|
|
|
|
** Returns : (void)
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
int heap_meminfo(heap_t *h);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Returns the total number of free bytes on the heap
|
|
|
|
** Parameters: (heap_t *) h: The heap to check
|
|
|
|
** Returns : (int) The total free space in bytes
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
int heap_largest(heap_t *h);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Returns the block size of the largest free block on the heap
|
|
|
|
** Parameters: (heap_t *) h: The heap to check
|
|
|
|
** Returns : (int) The size of the largest free block
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
heap_ptr heap_allocate(heap_t *h, int size);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Allocates memory on a heap.
|
|
|
|
** Parameters: (heap_t *) h: The heap to work with
|
|
|
|
** (int) size: The block size to allocate
|
|
|
|
** Returns : (heap_ptr): The heap pointer to the new block, or 0 on failure
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
void heap_free(heap_t *h, unsigned int m);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Frees allocated heap memory.
|
|
|
|
** Parameters: (heap_t *) h: The heap to work with
|
|
|
|
** (int) m: The handle at which memory is to be unallocated
|
|
|
|
** Returns : (void)
|
|
|
|
** This function automatically prevents fragmentation from happening.
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
void save_ff(heap_t *h);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Stores the current first free position
|
|
|
|
** Parameters: (heap_t *) h: The heap which is to be manipulated
|
|
|
|
** Returns : (void)
|
|
|
|
** This function can be used to save the heap state for later restoration (see
|
|
|
|
** the next function)
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
void restore_ff(heap_t *h);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Restores the first free heap state
|
|
|
|
** Parameters: (heap_t *) h: The heap to restore
|
|
|
|
** Returns : (void)
|
|
|
|
** Restoring the first free state will reset the heap to the position stored
|
|
|
|
** when save_ff() was called, if and only if none of the blocks allocated before
|
|
|
|
** save_ff() was called was ever freed ("ever" includes "before save_ff() was
|
|
|
|
** called").
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
void heap_dump_free(heap_t *h);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Dumps debugging information about the stack
|
|
|
|
** Parameters: (heap_t *) h: The heap to check
|
|
|
|
** Returns : (void)
|
|
|
|
*/
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
void heap_dump_all(heap_t *h);
|
2009-02-15 06:10:59 +00:00
|
|
|
/* Dumps all allocated/unallocated zones on the heap
|
|
|
|
** Parameters: (heap_t *) h: The heap to check
|
|
|
|
** Returns : (void)
|
|
|
|
*/
|
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|
|
|
|
|
2009-02-19 18:08:44 +00:00
|
|
|
#endif // !_SCI_HEAP_H
|