Newer
Older
rtlibc / inc / malloc.h
/* Copyright (C) Thornwave Labs Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
 */

#ifndef _RTLIBC_MALLOC_H
#define _RTLIBC_MALLOC_H


#include <stdint.h>
#include <stddef.h>
#include <stdbool.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_mask;
	size_t link_size;
	
	rtmalloc_block_link_t* free_list_head;
}rtmalloc_context_t;


bool 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