Data Fields
Memory_handler Struct Reference
Collaboration diagram for Memory_handler:
Collaboration graph

Data Fields

void * next
 
void * mem
 
unsigned int size
 
char used
 

Detailed Description

This file contains simple memory handler, and it routines. Memory handler allocates memory on need, and keeps list of memory in use, and memory used, but not currently in use.

This makes memory allocation and freeing easy and fast, since programmers dont need to care about memory allocation. This is nice with complex programgs, with lot's of places where there might be need for allocating memory. Also, in this way one don't need long argument lists for functions to give workspace addresses.

This version uses one-way linked list to keep track of used memory, and when allocating memory it first checks if there are free memory (so once allocated, then freed) memory pieces and chooses the best (less amount of wasted memory) of them. If such (used) memory piece is not available, it allocates such from free memory.

Note that because how this system works, it is recommandable to use little bigger memory than needed (or say standard size memory blocks, that are not fully used), so that they can be reused. Also, it is not recommendable to alloc and de-alloc memory in tight loop, since the algorithm goes through the whole list of free memory. Also, it might be a good idea to make clean-up once in a while to avoid memory being to fragmented.

If one is sure that memory allocated to workspace WILL NOT be used again, then use true_free_memory.

Version history: 2006-07 - Pauli: First createdStructure for one-way list to keep track of used memory

Field Documentation

◆ mem

void* Memory_handler::mem

◆ next

void* Memory_handler::next

◆ size

unsigned int Memory_handler::size

size of this allocated memory (in bytes)

Referenced by _free_memory(), allocate_memory(), debug_print_memory(), free_all_memory(), init_memory_handler(), swabip(), swawbip(), and swawip().

◆ used

char Memory_handler::used

Is this memory block used or free. 1 means 'in use' and 0 mean not in use, but allocated. -1 means not allocated

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


The documentation for this struct was generated from the following file: