Mercurial > repos > rhope
diff runtime/fixed_alloc.h @ 62:b218af069da7
merge
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 10 Oct 2009 16:43:37 -0400 |
parents | 1b86a1ee500a |
children | a24eb366195c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/fixed_alloc.h Sat Oct 10 16:43:37 2009 -0400 @@ -0,0 +1,40 @@ +#ifndef FIXED_ALLOC_H_ +#define FIXED_ALLOC_H_ + +#include <stddef.h> +#include "plat_types.h" +#include "block_alloc.h" + +#define GET_BLOCK(ptr) ((void*)(((uint32_t)(ptr))&(~(BLOCK_SIZE-1)))) + +#define MAX_SIZE (BLOCK_SIZE/32) +#define STRIDE (BLOCK_SIZE/1024) +#define MIN_SIZE (BLOCK_SIZE/1024) +#define MAX_FREE 16 + +#define ADJUST_SIZE(requested) (((requested)+(STRIDE-1)) & (~(STRIDE-1))) + + +#pragma pack(push,1) +typedef struct mem_block { + struct mem_block *next; + struct mem_block *last; + uint16_t numfree; + uint16_t firstfree; + uint8_t bitmap[1]; +} mem_block; +#pragma pack(pop) + +//num_elements = (BLOCK_SIZE - sizeof(mem_block)+1)*8/(sizeof(element)*8+1) +typedef struct { + mem_block *freelist; + mem_block *inuse[(MAX_SIZE-MIN_SIZE)/STRIDE]; + uint32_t freecount; +} mem_manager; + +void fixed_alloc_init(); +mem_manager * new_mem_manager(); +void * falloc(size_t size, mem_manager * manager); +void ffree(void * ptr, size_t size, mem_manager * manager); + +#endif //FIXED_ALLOC_H_