X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=mware%2Fheap.h;h=58a3a2fb81373ce3324e703f52215371b395c4cd;hb=9f411c91637c328ec9475ce6732df2e66c8b53de;hp=c81b728b01ab2e3186f7a63762d5a20979dd5667;hpb=daac0a9063cd094f8af9f8ccf3eb6b49e481a337;p=bertos.git diff --git a/mware/heap.h b/mware/heap.h index c81b728b..58a3a2fb 100755 --- a/mware/heap.h +++ b/mware/heap.h @@ -11,10 +11,18 @@ * \version $Id$ * * \author Bernardo Innocenti + * + * \todo Heap memory could be defined as an array of MemChunk, and used + * in this form also within the implementation. This would probably remove + * memory alignment problems, and also some aliasing issues. + * */ /* * $Log$ + * Revision 1.2 2004/08/04 15:54:18 rasky + * Merge da SC: prima versione veramente funzionante + * * Revision 1.1 2004/07/31 16:33:58 rasky * Spostato lo heap da kern/ a mware/ * @@ -26,22 +34,50 @@ * */ -#ifndef KERN_HEAP_H -#define KERN_HEAP_H +#ifndef MWARE_HEAP_H +#define MWARE_HEAP_H + +#include +#include + +struct _MemChunk; + +//! A heap +struct Heap +{ + struct _MemChunk *FreeList; //!< Head of the free list +}; + + +//! Initialize \a heap within the buffer pointed by \a memory which is of \a size bytes +void heap_init(struct Heap* heap, void* memory, size_t size); + +//! Allocate a chunk of memory of \a size bytes from the heap +void *heap_allocmem(struct Heap* heap, size_t size); + +//! Free a chunk of memory of \a size bytes from the heap +void heap_freemem(struct Heap* heap, void *mem, size_t size); + + +#define HNEW(heap, type) \ + (type*)heap_allocmem(heap, sizeof(type)) + +#define HNEWVEC(heap, type, nelem) \ + (type*)heap_allocmem(heap, sizeof(type) * (nelem)) + +#define HDELETE(heap, type, mem) \ + heap_freemem(heap, mem, sizeof(type)) -#include "compiler.h" +#define HDELETEVEC(heap, type, nelem, mem) \ + heap_freemem(heap, mem, sizeof(type) * (nelem)) -/* Memory allocation services */ -void heap_init(void); -void *heap_alloc(size_t size); -void heap_free(void *mem, size_t size); +#if CONFIG_HEAP_MALLOC -#ifdef __POSIX__ /* unused */ -void *malloc(size_t size); -void *calloc(unsigned int nelem, size_t size); -void free(void * mem); -#endif /* __POSIX__ */ +void *heap_malloc(struct Heap* heap, size_t size); +void *heap_calloc(struct Heap* heap, size_t size); +void heap_free(struct Heap* heap, void * mem); -#endif /* KERN_HEAP_H */ +#endif +#endif /* MWARE_HEAP_H */