remove <cstddef> and NULLs (use nullptr)
This commit is contained in:
@ -53,11 +53,11 @@ Allocator::Allocator() : heap_start(HEAP_START), heap_end(HEAP_START + HEAP_SIZE
|
||||
* Nachfolgend sind die Operatoren von C++, die wir hier ueberschreiben *
|
||||
* und entsprechend 'mm_alloc' und 'mm_free' aufrufen. *
|
||||
*****************************************************************************/
|
||||
void* operator new(size_t size) {
|
||||
void* operator new(std::size_t size) {
|
||||
return allocator.alloc(size);
|
||||
}
|
||||
|
||||
void* operator new[](size_t count) {
|
||||
void* operator new[](std::size_t count) {
|
||||
return allocator.alloc(count);
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,6 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "kernel/Globals.h"
|
||||
#include <stddef.h>
|
||||
// #include "kernel/allocator/LinkedListAllocator.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: BumpAllocator::init *
|
||||
@ -55,7 +53,7 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
if (req_size + (unsigned int)this->next > this->heap_end) {
|
||||
log.error() << " - More memory requested than available :(" << endl;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* allocated = this->next;
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "kernel/allocator/LinkedListAllocator.h"
|
||||
#include "kernel/Globals.h"
|
||||
#include "user/lib/Logger.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// I don't order the list by size so that the block order corresponds to the location in memory
|
||||
// Then I can easily merge adjacent free blocks by finding the previous block without looking at
|
||||
@ -52,7 +51,7 @@ void LinkedListAllocator::dump_free_memory() {
|
||||
|
||||
kout << "Freier Speicher:" << endl;
|
||||
|
||||
if (this->free_start == NULL) {
|
||||
if (this->free_start == nullptr) {
|
||||
kout << " - No free Blocks" << endl;
|
||||
} else {
|
||||
kout << " - Freelist start: " << hex << (unsigned int)this->free_start << endl;
|
||||
@ -79,10 +78,10 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
log.debug() << "Requested " << hex << req_size << " Bytes" << endl;
|
||||
|
||||
if (this->free_start == NULL) {
|
||||
if (this->free_start == nullptr) {
|
||||
log.error() << " - No free memory remaining :(" << endl;
|
||||
this->lock.release();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Round to word borders
|
||||
@ -130,7 +129,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
if (this->free_start == current) {
|
||||
// No free block remaining
|
||||
log.trace() << " - Disabled freelist" << endl;
|
||||
this->free_start = NULL;
|
||||
this->free_start = nullptr;
|
||||
}
|
||||
|
||||
log.trace() << " - Allocated " << hex << current->size << " Bytes without cutting" << endl;
|
||||
@ -166,7 +165,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
log.error() << " - More memory requested than available :(" << endl;
|
||||
this->lock.release();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -192,7 +191,7 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
|
||||
// Reenable the freelist if no block was available
|
||||
// This also means that no merging can be done
|
||||
if (this->free_start == NULL) {
|
||||
if (this->free_start == nullptr) {
|
||||
this->free_start = block_start;
|
||||
block_start->allocated = false;
|
||||
block_start->next = block_start;
|
||||
@ -296,7 +295,6 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
this->lock.release();
|
||||
}
|
||||
|
||||
// NOTE: I added this
|
||||
free_block_t* LinkedListAllocator::find_previous_block(free_block_t* next_block) {
|
||||
// Durchlaufe die ganze freispeicherliste bis zum Block der auf next_block zeigt
|
||||
free_block_t* current = next_block;
|
||||
|
@ -32,7 +32,7 @@ typedef struct free_block {
|
||||
class LinkedListAllocator : Allocator {
|
||||
private:
|
||||
// freie Bloecke werden verkettet
|
||||
struct free_block* free_start;
|
||||
struct free_block* free_start = nullptr;
|
||||
|
||||
LinkedListAllocator(Allocator& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
|
@ -1,15 +1,12 @@
|
||||
#include "kernel/allocator/TreeAllocator.h"
|
||||
#include "kernel/Globals.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// NOTE: I added this file
|
||||
|
||||
void TreeAllocator::init() {
|
||||
this->free_start = (tree_block_t*)this->heap_start;
|
||||
this->free_start->allocated = false;
|
||||
this->free_start->left = NULL;
|
||||
this->free_start->right = NULL;
|
||||
this->free_start->parent = NULL;
|
||||
this->free_start->left = nullptr;
|
||||
this->free_start->right = nullptr;
|
||||
this->free_start->parent = nullptr;
|
||||
this->free_start->red = false; // The root is always black
|
||||
this->free_start->next = (list_block_t*)this->free_start;
|
||||
this->free_start->previous = (list_block_t*)this->free_start;
|
||||
@ -47,14 +44,14 @@ void* TreeAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
// Finds smallest block that is large enough
|
||||
tree_block_t* best_fit = this->rbt_search_bestfit(rreq_size);
|
||||
if (best_fit == NULL) {
|
||||
if (best_fit == nullptr) {
|
||||
log.error() << " - No block found" << endl;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (best_fit->allocated) {
|
||||
// Something went really wrong
|
||||
log.error() << " - Block already allocated :(" << endl;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
best_fit->allocated = true;
|
||||
unsigned int size = this->get_size(best_fit);
|
||||
|
@ -4,8 +4,7 @@
|
||||
#include "kernel/Allocator.h"
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
// NOTE: I added this file
|
||||
// NOTE: I can't imagine that this is very fast with all the tree logic?
|
||||
// I can't imagine that this is fast with all the tree logic?
|
||||
|
||||
typedef struct list_block {
|
||||
// Doubly linked list for every block
|
||||
|
@ -1,13 +1,11 @@
|
||||
#include "kernel/allocator/TreeAllocator.h"
|
||||
#include "kernel/Globals.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// NOTE: I added this file
|
||||
// NOTE: RBT code taken from https://github.com/Bibeknam/algorithmtutorprograms
|
||||
// RBT code taken from https://github.com/Bibeknam/algorithmtutorprograms
|
||||
|
||||
// START copy from algorithmtutorprograms
|
||||
void TreeAllocator::rbt_transplant(tree_block_t* a, tree_block_t* b) {
|
||||
if (a->parent == NULL) {
|
||||
if (a->parent == nullptr) {
|
||||
this->free_start = b;
|
||||
} else if (a == a->parent->left) {
|
||||
a->parent->left = b;
|
||||
@ -21,15 +19,15 @@ void TreeAllocator::rbt_transplant(tree_block_t* a, tree_block_t* b) {
|
||||
// and fix the tree
|
||||
void TreeAllocator::rbt_insert(tree_block_t* node) {
|
||||
// Ordinary Binary Search Insertion
|
||||
node->parent = NULL;
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
node->parent = nullptr;
|
||||
node->left = nullptr;
|
||||
node->right = nullptr;
|
||||
node->red = true; // new node must be red
|
||||
|
||||
tree_block_t* y = NULL;
|
||||
tree_block_t* y = nullptr;
|
||||
tree_block_t* x = this->free_start;
|
||||
|
||||
while (x != NULL) {
|
||||
while (x != nullptr) {
|
||||
y = x;
|
||||
if (this->get_size(node) < this->get_size(x)) {
|
||||
x = x->left;
|
||||
@ -40,7 +38,7 @@ void TreeAllocator::rbt_insert(tree_block_t* node) {
|
||||
|
||||
// y is parent of x
|
||||
node->parent = y;
|
||||
if (y == NULL) {
|
||||
if (y == nullptr) {
|
||||
this->free_start = node;
|
||||
} else if (this->get_size(node) < this->get_size(y)) {
|
||||
y->left = node;
|
||||
@ -49,13 +47,13 @@ void TreeAllocator::rbt_insert(tree_block_t* node) {
|
||||
}
|
||||
|
||||
// if new node is a root node, simply return
|
||||
if (node->parent == NULL) {
|
||||
if (node->parent == nullptr) {
|
||||
node->red = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// if the grandparent is null, simply return
|
||||
if (node->parent->parent == NULL) {
|
||||
if (node->parent->parent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -118,7 +116,7 @@ void TreeAllocator::rbt_fix_insert(tree_block_t* k) {
|
||||
void TreeAllocator::rbt_rot_l(tree_block_t* x) {
|
||||
tree_block_t* y = x->right;
|
||||
x->right = y->left;
|
||||
if (y->left != NULL) {
|
||||
if (y->left != nullptr) {
|
||||
y->left->parent = x;
|
||||
}
|
||||
y->parent = x->parent;
|
||||
@ -137,7 +135,7 @@ void TreeAllocator::rbt_rot_l(tree_block_t* x) {
|
||||
void TreeAllocator::rbt_rot_r(tree_block_t* x) {
|
||||
tree_block_t* y = x->left;
|
||||
x->left = y->right;
|
||||
if (y->right != NULL) {
|
||||
if (y->right != nullptr) {
|
||||
y->right->parent = x;
|
||||
}
|
||||
y->parent = x->parent;
|
||||
@ -154,7 +152,7 @@ void TreeAllocator::rbt_rot_r(tree_block_t* x) {
|
||||
|
||||
// find the node with the minimum key
|
||||
tree_block_t* TreeAllocator::rbt_minimum(tree_block_t* node) {
|
||||
while (node->left != NULL) {
|
||||
while (node->left != nullptr) {
|
||||
node = node->left;
|
||||
}
|
||||
return node;
|
||||
@ -166,10 +164,10 @@ void TreeAllocator::rbt_remove(tree_block_t* z) {
|
||||
|
||||
y = z;
|
||||
bool y_original_red = y->red;
|
||||
if (z->left == NULL) {
|
||||
if (z->left == nullptr) {
|
||||
x = z->right;
|
||||
this->rbt_transplant(z, z->right);
|
||||
} else if (z->right == NULL) {
|
||||
} else if (z->right == nullptr) {
|
||||
x = z->left;
|
||||
this->rbt_transplant(z, z->left);
|
||||
} else {
|
||||
@ -264,14 +262,14 @@ void TreeAllocator::rbt_fix_remove(tree_block_t* x) {
|
||||
}
|
||||
// END copy from algorithmtutorprograms
|
||||
|
||||
// NOTE: This is recursive and depends on luck
|
||||
// This is recursive and depends on luck
|
||||
tree_block_t* TreeAllocator::rbt_search_bestfit(tree_block_t* node, unsigned int req_size) {
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
if (node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (req_size < this->get_size(node)) {
|
||||
if (node->left != NULL && this->get_size(node->left) >= req_size) {
|
||||
if (node->left != nullptr && this->get_size(node->left) >= req_size) {
|
||||
return this->rbt_search_bestfit(node->left, req_size);
|
||||
}
|
||||
|
||||
@ -279,12 +277,12 @@ tree_block_t* TreeAllocator::rbt_search_bestfit(tree_block_t* node, unsigned int
|
||||
}
|
||||
|
||||
if (req_size > this->get_size(node)) {
|
||||
if (node->right != NULL && this->get_size(node->right) >= req_size) {
|
||||
if (node->right != nullptr && this->get_size(node->right) >= req_size) {
|
||||
return this->rbt_search_bestfit(node->right, req_size);
|
||||
}
|
||||
|
||||
// Block doesn't fit
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Perfect fit
|
||||
|
@ -11,7 +11,6 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "kernel/Globals.h"
|
||||
#include "kernel/Paging.h"
|
||||
#include "user/MainMenu.h"
|
||||
|
||||
void print_startup_message() {
|
||||
@ -90,7 +89,7 @@ int main() {
|
||||
// DONE: Array wrapper
|
||||
// DONE: Rewrite Logging with a basic logger
|
||||
// DONE: Static Logger
|
||||
// CANCELED: String wrapper
|
||||
// DONE: String wrapper
|
||||
// DONE: Linked List
|
||||
// DONE: Iterator support for structures
|
||||
// DONE: Implement own basic managed pointers
|
||||
@ -118,7 +117,7 @@ int main() {
|
||||
// Or check if thread is still running
|
||||
// TODO: Delete copy constructors that weren't already deleted
|
||||
// DONE: Switch out semaphore Queue with ArrayList? Or switch back Scheduler to Queue?
|
||||
// TODO: Add virtual destructors and make sure to call them with delete when objects are removed
|
||||
// CANCELED: Add virtual destructors and make sure to call them with delete when objects are removed
|
||||
// TODO: Replace empty constructors/destructors with default keyword
|
||||
// DONE: Synchronize the outstream
|
||||
// DONE: Remove Iterator from List.h
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define __ARRAY_INCLUDE_H
|
||||
|
||||
#include "user/lib/Iterator.h"
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
namespace bse {
|
||||
|
@ -2,8 +2,7 @@
|
||||
#define __String_Include_H_
|
||||
|
||||
#include "user/lib/Array.h"
|
||||
#include <cstddef>
|
||||
#include <user/lib/Iterator.h>
|
||||
#include "user/lib/Iterator.h"
|
||||
|
||||
namespace bse {
|
||||
|
||||
|
Reference in New Issue
Block a user