Update markdown and tabs and stuff

This commit is contained in:
2016-10-22 17:07:50 +02:00
parent 67e817490e
commit a27daafa0a
39 changed files with 2249 additions and 2139 deletions

View File

@@ -26,19 +26,19 @@ Now, let's look at a few ways to do this.
The simplest possible memory manager just hands out a new address each time
_malloc_ is called and doesn't care when memory is freed.
uint32_t memory_pointer = HEAP_START;
:::c
uint32_t memory_pointer = HEAP_START;
void *malloc(uint32_t size);
{
memory_pointer = memory_pointer + size;
return memory_pointer - size;
}
void *malloc(uint32_t size);
{
memory_pointer = memory_pointer + size;
return memory_pointer - size;
}
void free(void *mem)
{
;
}
{: .prettyprint}
void free(void *mem)
{
;
}
###Heap
The next method - which I prefer - is a memory heap.
@@ -46,33 +46,33 @@ The next method - which I prefer - is a memory heap.
The heap consists of a list of free memory areas. In the simplest possible
variety, it would look something like this:
struct area_header
{
uint32_t size;
struct free_area *next;
};
void *malloc(uint32_t size)
{
struct area_header *area = heap_list_head;
while(area)
{
if(area->size >= size)
{
remove_from_heap_list(area);
return get_memory_area(area);
}
area = area->next;
}
panic("Out of memory!");
}
void free(void *mem)
{
struct area_header area = get_area_header(mem);
insert_into_heap_list(area);
}
{: .prettyprint}
:::c
struct area_header
{
uint32_t size;
struct free_area *next;
};
void *malloc(uint32_t size)
{
struct area_header *area = heap_list_head;
while(area)
{
if(area->size >= size)
{
remove_from_heap_list(area);
return get_memory_area(area);
}
area = area->next;
}
panic("Out of memory!");
}
void free(void *mem)
{
struct area_header area = get_area_header(mem);
insert_into_heap_list(area);
}
Here it is assumed that the free memory is already divided into smaller areas
that each start with an *area_header* structure as in the figure below. If the