Data Structures | Functions | Variables
memory_handler.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "include/memory_handler.h"
Include dependency graph for memory_handler.c:

Data Structures

struct  Memory_handler

Functions

void _free_memory (void *memory, int true_f)
int init_memory_handler ()
void fill_memory (void *mem)
int check_memory (void *mem)
void * allocate_memory (int size)
void free_memory (void *memory)
void true_free_memory (void *memory)
void free_all_memory ()
void debug_print_memory ()

Variables

struct Memory_handlerMEM_HANDLE = NULL

Function Documentation

void _free_memory ( void *  memory,
int  true_f 
)

For internal use only

Marks memory as freed, optionally actually frees the memory

Parameters:
memorypointer to memory
true_f1 for actual freeing

References check_memory(), DEBUG, DEBUG_BUFFER_BORDER, Memory_handler::mem, MEM_HANDLE, Memory_handler::next, Memory_handler::size, and Memory_handler::used.

Referenced by free_memory(), and true_free_memory().

Here is the call graph for this function:

void* allocate_memory ( int  size)

Allocate memory for atleast size bytes.

Parameters:
sizesize of memory in bytes
Returns:
pointer to memory if ok NULL if out of memory

References DEBUG, DEBUG_BUFFER_BORDER, fill_memory(), Memory_handler::mem, MEM_HANDLE, Memory_handler::next, Memory_handler::size, and Memory_handler::used.

Here is the call graph for this function:

int check_memory ( void *  mem)

Checks that memory usage of mem has not borders on both sides

Parameters:
mempointer to memory

References DEBUG, DEBUG_BUFFER_BORDER, and DEBUG_BUFFER_VALUE.

Referenced by _free_memory().

void debug_print_memory ( )

Debug printing. Prints usage of memory and some info.

References DEBUG, Memory_handler::mem, MEM_HANDLE, Memory_handler::next, Memory_handler::size, and Memory_handler::used.

void fill_memory ( void *  mem)

Fills memory with DEBUG_BUFFER_VALUE for DEBUG_BUFFER_BORDER bytes

Parameters:
mempointer to memory

References DEBUG_BUFFER_BORDER, and DEBUG_BUFFER_VALUE.

Referenced by allocate_memory().

void free_all_memory ( )

Free all memory, permanently. Used as clean_up() function.

References Memory_handler::mem, Memory_handler::next, Memory_handler::size, and Memory_handler::used.

void free_memory ( void *  memory)

Sets memory free for re-use, but does not actually free any memory

Parameters:
memory

References _free_memory().

Here is the call graph for this function:

int init_memory_handler ( )

Initializes this whole handler thingie. MUST BE CALLED

Returns:
0 - on success, 1 - on failure (out of memory )

References DEBUG, Memory_handler::mem, Memory_handler::next, Memory_handler::size, and Memory_handler::used.

void true_free_memory ( void *  memory)

Does the really freeing memory, deallocates the memory.

Parameters:
memorypointer to memory

References _free_memory().

Here is the call graph for this function:


Variable Documentation

struct Memory_handler* MEM_HANDLE = NULL

Global handle for memory handler

Referenced by _free_memory(), allocate_memory(), and debug_print_memory().