home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
memmanagement
/
slflex_1
/
h
/
flex
Wrap
Text File
|
1995-03-25
|
4KB
|
161 lines
/*
* flex.h
*
* A shifting heap
*
* © 1994 Straylight
*/
#ifndef __flex_h
#define __flex_h
/*----- How it all works --------------------------------------------------*
*
* In order to allow the blocks to move around, you need to tell flex where
* your pointer to each block is. You do this with an anchor pointer (i.e.
* it points at your anchor for the block). Flex is quite at liberty to
* change your anchors at any time it wants to, so if you don't want your
* blocks to move, don't call flex. You must ensure that you always access
* data in flex blocks through the anchor, unless you're really sure the
* block won't move.
*
* Unlike older (Acorn) versions, Straylight flex doesn't ensure that the
* heap is always as compact as possible. Instead, calling flex_reduce will
* attempt to compact the heap a little bit, so if you call it a lot, the
* heap will eventually become very compact. It is envisaged that you call
* flex_reduce every Wimp_Poll.
*
* There is another call, flex_compact, which will compact the heap fully.
* This isn't terribly useful most of the time, since flex compacts itself
* if it runs out of memory.
*
* flex_budge is not currently supported. If there is a demand for it,
* it may be added in later.
*/
/*
* A flex anchor pointer
*/
typedef void **flex_ptr;
/*
* void flex_init(void)
*
* Use
* Initialises the flex system. It doesn't check that any memory is
* available.
*/
void flex_init(void);
/*
* int flex_alloc(flex_ptr anchor,int size)
*
* Use
* Allocates size bytes of memory from the flex heap.
*
* Note that if there are no blocks currently allocated prior to making
* this call, the block allocated will not be moved by flex.
*
* Parameters
* flex_ptr anchor == the address of your anchor for this block
* int size == size in bytes of the block
*
* Returns
* 0 if it failed.
*/
int flex_alloc(flex_ptr anchor,int size);
/*
* void flex_free(flex_ptr anchor)
*
* Use
* Informs flex that the block pointed to by *anchor isn't useful any
* more.
*/
void flex_free(flex_ptr anchor);
/*
* int flex_extend(flex_ptr anchor,int newsize)
*
* Use
* Changes the size of the block pointed to by *anchor. Note that newsize
* is the *NEW SIZE* you want, not an adjustment to the current size as
* in flex_midextend.
*
* Parameters
* flex_ptr anchor == the block to resize
* int newsize == the size to make it
*
* Returns
* 0 if it failed
*/
int flex_extend(flex_ptr anchor,int newsize);
/*
* int flex_midextend(flex_ptr anchor,int at,int by)
*
* Use
* Inserts or removes `by' bytes from the block at index `at'. The insert
* or delete is always performed so that the byte that was at `at' is now at
* `at'+`by'. Values of `at' allowable are 0 to flex__size(anchor), and
* values of `by' allowable are -flex__size(anchor) to INT_MAX.
*
* Parameters
* flex_ptr anchor == pointer to the anchor for the block
* int at == index at which to extend the block
* int by == how much to extend the block by
*
* Returns
* 0 if it failed
*/
int flex_midextend(flex_ptr anchor,int at,int by);
/*
* int flex_size(flex_ptr anchor)
*
* Use
* Tells you how big a flex block is
*
* Parameters
* flex_ptr anchor == pointer to the block to find size of
*
* Returns
* Currently allocated size in bytes.
*/
int flex_size(flex_ptr anchor);
/*
* void flex_reduce(void)
*
* Use
* Compacts the heap a bit. Call it every now and then.
*/
void flex_reduce(void);
/*
* void flex_compact(void)
*
* Use
* Fully compacts the heap.
*/
void flex_compact(void);
/* --- kernel slot extension functions --- *
*
* Only flex_dont_budge is supported at the moment.
*/
int flex_dont_budge(int n,void **p);
int flex_budge(int n,void **p);
#endif