#ifndef HAVEN_ALLOC_H
# define HAVEN_ALLOC_H

#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <assert.h>

// ================================================================
// Memory System Core
// ================================================================

/**
 * @brief
 *
 */
void	memory_system_init();

/**
 * @brief
 *
 */
void	memory_system_shutdown();

/**
 * @brief
 *
 */
void	memory_system_print();

// ================================================================
// Stack Allocator (Temporary/Fast)
// ================================================================

/**
 * @brief return a pointer to position x in stack buffer
 *
 * @param size
 * @param alignment
 * @return void*
 */
void	*allocator_stack_alloc(size_t size, size_t alignment);

/**
 * @brief call this function to reset memory offset
 * and  swap stack memory buffer (in this order)
 *
 */
void	allocator_stack_swap(void);

/**
 * @brief
 *
 */
void	allocator_stack_init(void);

/**
 * @brief
 *
 */
void	allocator_stack_delete(void);

// ================================================================
// Pool Allocator (Fixed-Size Objects) WIP
// ================================================================


#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>

#include <string.h>

typedef struct {
	uint32_t	total_allocation;

	size_t		total_allocated;

	size_t		total_freed;

	size_t		current_allocated;
}	memory_stats;

typedef struct {
	bool	used;
	size_t	size;
	void*	ptr;
}	memory_page;

#define BASE_STACK_SIZE 67108864 //64Mb

typedef struct {
	size_t		size;
	size_t		offset;
	uint8_t*	base;
}	allocator_stack;


#endif