Newer
Older
rtlibc / inc / malloc.h
@Razvan Turiac Razvan Turiac on 19 Dec 2019 798 bytes Improved code.
#ifndef _RTLIBC_MALLOC_H
#define _RTLIBC_MALLOC_H

#include <stdint.h>
#include <stddef.h>


#ifdef __cplusplus
extern "C"
{
#endif


typedef struct rtmalloc_block_link_s
{
	size_t size;
	struct rtmalloc_block_link_s *next;
}rtmalloc_block_link_t;


typedef struct
{
	size_t alignment;
	size_t alignment_mask;
	size_t allocated_mask;
	
	size_t size_free;
	size_t size_free_min;
	size_t min_block_size;

	rtmalloc_block_link_t free_list_head;
	rtmalloc_block_link_t *free_list_tail;
}rtmalloc_context_t;


void rtmalloc_init(rtmalloc_context_t *context, void *heap, size_t size, size_t alignment);
void* rtmalloc(rtmalloc_context_t *context, size_t size);
void rtfree(rtmalloc_context_t *context, void *p);
size_t rtmsize(rtmalloc_context_t *context, void *p);


#ifdef __cplusplus
}
#endif

#endif