/*->h.flex */

/****************************************************************************
 * This source file was written by Acorn Computers Limited. It is part of   *
 * the "cwimp" library for writing applications in C for RISC OS. It may be *
 * used freely in the creation of programs for Archimedes. It should be     *
 * used with Acorn's C Compiler Release 2 or later.                         *
 *                                                                          *
 * No support can be given to programmers using this code and, while we     *
 * believe that it is correct, no correspondence can be entered into        *
 * concerning behaviour or bugs.                                            *
 *                                                                          *
 * Upgrades of this code may or may not appear, and while every effort will *
 * be made to keep such upgrades upwards compatible, no guarantees can be   *
 * given.                                                                   *
 ***************************************************************************/

/*
 * Title  : h.flex
 * Purpose: provide memory allocation for interactive programs requiring
 *          large chunks of store. Such programs must respond to memory
 *          full errors, and must not suffer from fragmentation.
 * Version: 0.1
 */


typedef void **flex_ptr;

int flex_alloc(flex_ptr anchor, int n);
int flex_alloce(flex_ptr anchor, int n);

/* Allocates n bytes of store, which must always be accessed indirectly via
*anchor (i.e. (*anchor)[0]..(*anchor)[n-1]). The first argument should be &
of some char* variable. flex retains knowledge of this address, so that it
can move the allocated store if necessary, updating this char* variable.
Because of this the allocated store should always be accessed via this
variable. Returns 0 in *anchor, with situation unchanged, if there is not
enough store. */

void flex_free(flex_ptr anchor);
/* sets *anchor to 0 */

int flex_size(flex_ptr);
/* returns the exact number of bytes in the flexible store area. */

int flex_extend(flex_ptr, int newsize);
int flex_extende(flex_ptr, int newsize);
/* The flexible store area is extended or truncated to have the new size.
Returns 0 (with situation unchanged) if there is not enough store, this can
only happen if extension is being requested. Otherwise, returns 1. */

int flex_midextend(flex_ptr, int at, int by);
int flex_midextende(flex_ptr, int at, int by);
/* If by is positive then the flexible store area is extended, and locations
above (at) are copied up by (by). If by is negative then the flexible store
area is reduced, and any bytes beyond (at) are copied down to (at+by).
Returns FALSE (with situation unchanged) if there is not enough store, this
can only happen if by is positive. */

int flex_storefree(void);
/* A number to tell the user, i.e. only approximate: number of bytes free. */

void flex_init(void);
/* should be called before any other calls to this interface. */


int flex_chunk(flex_ptr anchor,int size,int chunksize);
int flex_chunke(flex_ptr anchor,int size,int chunksize);

