Merged the unaligned and aligned heap APIs and simplified the code.

This commit is contained in:
Michael Brown
2005-05-12 16:34:57 +00:00
parent a5a14dc05d
commit eff4fa5a04
2 changed files with 123 additions and 88 deletions

62
src/include/heap.h Normal file
View File

@@ -0,0 +1,62 @@
#ifndef HEAP_H
#define HEAP_H
/*
* Allocate a block with specified (physical) alignment
*
* "align" must be a power of 2.
*
* Note that "align" affects the alignment of the physical address,
* not the virtual address. This is almost certainly what you want.
*
*/
extern void * emalloc ( size_t size, unsigned int align );
/*
* Allocate a block, with no particular alignment requirements.
*
*/
static inline void * malloc ( size_t size ) {
return emalloc ( size, sizeof ( void * ) );
}
/*
* Allocate all remaining space on the heap
*
*/
extern void * emalloc_all ( size_t *size );
/*
* Free a block.
*
* The caller must ensure that the block being freed is the last (most
* recent) block allocated on the heap, otherwise heap corruption will
* occur.
*
*/
extern void efree ( void *ptr );
static inline void free ( void *ptr ) {
efree ( ptr );
}
/*
* Free all allocated blocks on the heap
*
*/
extern void efree_all ( void );
/*
* Resize a block.
*
* The caller must ensure that the block being resized is the last
* (most recent) block allocated on the heap, otherwise heap
* corruption will occur.
*
*/
static inline void * erealloc ( void *ptr, size_t size, unsigned int align ) {
efree ( ptr );
return emalloc ( size, align );
}
#endif /* HEAP_H */