1

fixed wrong bump allocator init

This commit is contained in:
churl
2022-05-07 14:30:40 +02:00
parent f6789b3950
commit 7f3c70f87a
10 changed files with 61 additions and 73 deletions

21
c_os/kernel/allocator/BumpAllocator.cc Normal file → Executable file
View 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;
}