4 * A heap system in a flex block
6 * © 1993-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Steel library.
13 * Steel is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Steel is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with Steel. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 typedef unsigned int size_t; /* from <stddef.h> */
36 typedef struct heap_infostr
38 int size; /* Size of the whole heap */
39 int free; /* Heap space currently free */
40 int largest; /* Size of the largest block */
45 * void heap_init(void)
48 * Initialises the heap system for use. This must be called before
49 * flex_alloc to ensure that the system gets the first block and so it
50 * doesn't move around. heap doesn't mind this, but your data probably will
51 * (if it doen't, why don't you use flex?).
57 * heap_infostr heap_info(void)
60 * Describes the heap's current status.
63 * Structure type described above.
66 heap_infostr heap_info(void);
69 * void *heap_alloc(size_t size)
72 * Allocates a block of at least a given size from a heap. If the heap is
73 * not big enough, more is claimed from the operating system. A NULL
74 * pointer is returned if a block of suitable size could not be found.
77 * size_t size == size of block required
83 void *heap_alloc(size_t size);
86 * void heap_free(void *block)
89 * Frees a block allocated using heap_alloc. It tries to shrink the heap
90 * as much as possible and to coagulate adjacent free blocks together.
93 * void *block == pointer to the block to free
96 void heap_free(void *block);
99 * void *heap_realloc(void *block,int newSize)
102 * Changes the size of a heap block. If possible, the block's position is
103 * is unchanged, but this may not always be the case.
105 * Note that changing a block's size to 0 is permitted. Passing a NULL
106 * pointer will probably result in severe heap death.
109 * void *block == pointer to the block to change
110 * int newSize == the new size to make the block
113 * Pointer to where the block has been moved to, or a NULL pointer if the
117 void *heap_realloc(void *block,int newSize);