fixed wrong bump allocator init
This commit is contained in:
21
c_os/kernel/allocator/BumpAllocator.cc
Normal file → Executable file
21
c_os/kernel/allocator/BumpAllocator.cc
Normal file → Executable file
@ -22,13 +22,12 @@ void BumpAllocator::init() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
this->heap_start = 3 * 1024 * 1024; // 3 MB
|
||||
this->heap_size = 1 * 1024 * 1024; // 1 MB
|
||||
this->heap_end = this->heap_start + this->heap_size; // 4 MB
|
||||
this->allocations = 0;
|
||||
this->next = (unsigned char*)heap_start;
|
||||
|
||||
this->initialized = true;
|
||||
kout << "Initialized Bump Allocator" << endl
|
||||
<< "Heap Start: " << hex << this->heap_start << ", Heap End: " << this->heap_end << endl;
|
||||
kout << endl;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -39,9 +38,10 @@ void BumpAllocator::init() {
|
||||
void BumpAllocator::dump_free_memory() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
kout << "Freier Speicher:" << endl
|
||||
<< " Heap Start: " << this->heap_start << ", Heap End: " << this->heap_end << endl
|
||||
<< " Next: " << this->next << ", Allocations: " << this->allocations << endl;
|
||||
<< "Next: " << hex << this->next << ", Allocations: " << dec << this->allocations << endl;
|
||||
kout << endl;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -53,13 +53,11 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
if (!this->initialized) {
|
||||
kout << "Allocator not initialized :(" << endl;
|
||||
return NULL;
|
||||
}
|
||||
kout << "Requested " << dec << req_size << " Bytes" << endl;
|
||||
|
||||
if (req_size > this->heap_end - (unsigned int)this->next) {
|
||||
kout << "More memory requested than available :(" << endl;
|
||||
kout << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -67,6 +65,9 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
||||
this->next = this->next + req_size;
|
||||
this->allocations = this->allocations + 1;
|
||||
|
||||
kout << "Allocated " << dec << req_size << " Bytes." << endl;
|
||||
kout << endl;
|
||||
|
||||
return allocated;
|
||||
}
|
||||
|
||||
|
||||
2
c_os/kernel/allocator/BumpAllocator.h
Normal file → Executable file
2
c_os/kernel/allocator/BumpAllocator.h
Normal file → Executable file
@ -23,7 +23,7 @@ private:
|
||||
BumpAllocator(Allocator& copy); // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
BumpAllocator() {}
|
||||
BumpAllocator() {}; // Allocator() called implicitely in C++
|
||||
|
||||
void init();
|
||||
void dump_free_memory();
|
||||
|
||||
27
c_os/kernel/allocator/LinkedListAllocator.cc
Normal file → Executable file
27
c_os/kernel/allocator/LinkedListAllocator.cc
Normal file → Executable file
@ -9,12 +9,11 @@
|
||||
* Autor: Michael Schoettner, HHU, 13.6.2020 *
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "kernel/Globals.h"
|
||||
#include "kernel/allocator/LinkedListAllocator.h"
|
||||
#include "kernel/Globals.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define HEAP_MIN_FREE_BLOCK_SIZE 64 // min. Groesse eines freien Blocks
|
||||
|
||||
#define HEAP_MIN_FREE_BLOCK_SIZE 64 // min. Groesse eines freien Blocks
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: LinkedListAllocator::init *
|
||||
@ -28,11 +27,9 @@
|
||||
*****************************************************************************/
|
||||
void LinkedListAllocator::init() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: LinkedListAllocator::dump_free_memory *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -40,31 +37,25 @@ void LinkedListAllocator::init() {
|
||||
*****************************************************************************/
|
||||
void LinkedListAllocator::dump_free_memory() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: LinkedListAllocator::alloc *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Einen neuen Speicherblock allozieren. *
|
||||
*****************************************************************************/
|
||||
void * LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: LinkedListAllocator::free *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Einen Speicherblock freigeben. *
|
||||
*****************************************************************************/
|
||||
void LinkedListAllocator::free(void *ptr) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
void LinkedListAllocator::free(void* ptr) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
}
|
||||
|
||||
|
||||
25
c_os/kernel/allocator/LinkedListAllocator.h
Normal file → Executable file
25
c_os/kernel/allocator/LinkedListAllocator.h
Normal file → Executable file
@ -14,30 +14,27 @@
|
||||
|
||||
#include "kernel/Allocator.h"
|
||||
|
||||
|
||||
// Format eines freien Blocks
|
||||
struct free_block {
|
||||
unsigned int size;
|
||||
struct free_block *next;
|
||||
struct free_block* next;
|
||||
};
|
||||
|
||||
|
||||
class LinkedListAllocator : Allocator {
|
||||
|
||||
private:
|
||||
// freie Bloecke werden verkettet
|
||||
struct free_block *free_start;
|
||||
|
||||
LinkedListAllocator(Allocator ©); // Verhindere Kopieren
|
||||
private:
|
||||
// freie Bloecke werden verkettet
|
||||
struct free_block* free_start;
|
||||
|
||||
LinkedListAllocator(Allocator& copy); // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
LinkedListAllocator () { }
|
||||
|
||||
void init ();
|
||||
void dump_free_memory ();
|
||||
void* alloc (unsigned int req_size);
|
||||
void free (void *ptr);
|
||||
LinkedListAllocator() {}
|
||||
|
||||
void init();
|
||||
void dump_free_memory();
|
||||
void* alloc(unsigned int req_size);
|
||||
void free(void* ptr);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user