/* Chunk based memory allocation system V1.02 11/2/08
   Copyright 2008 Jeffrey Lee
   This file is part of WOUM.
   WOUM 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 3 of the License, or
   (at your option) any later version.
   WOUM 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 WOUM.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _CBMA_H
#define _CBMA_H

typedef void *cbma_heap; /* A heap of fixed size memory blocks */

extern cbma_heap cbma_new(int size,int chunksize); /* Create an empty heap, suitable for objects of size 'size' bytes (Which must be a multiple of 4). Internally, 'chunksize' objects are stored per memory block allocated. Returns 0 on failure. */
extern void cbma_delete(cbma_heap h); /* Delete h and all its contents */
extern void cbma_empty(cbma_heap h); /* Empty h of its contents; all memory blocks will be freed, but h will remain ready for reuse */
extern void *cbma_alloc(cbma_heap h); /* Return a new data item, or 0 for failure */
extern void cbma_free(cbma_heap h,void *v); /* Add 'v' to the list of free items; no actual memory is freed, so the h structure will never shrink (Unless cbma_empty is called). */
extern int cbma_alloced(cbma_heap h); /* Return number of items currently allocated (doesn't include count in free list) */

#endif
