view runtime/fixed_alloc.h @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents d1569087348f
children 5a195ee08eac
line wrap: on
line source

#ifndef FIXED_ALLOC_H_
#define FIXED_ALLOC_H_

#include <stddef.h>
#include "plat_types.h"
#include "block_alloc.h"

#define GET_BLOCK(ptr) ((void*)(((uintptr_t)(ptr))&(~((uintptr_t)(BLOCK_SIZE-1)))))

#define MAX_SIZE   (BLOCK_SIZE/32)
#define STRIDE     (BLOCK_SIZE/1024)
#define MIN_SIZE   (BLOCK_SIZE/1024)
#define MAX_FREE   64

#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_