From 7b128b33c97060bb5a76be8d969d5318fb2cf65c Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Wed, 15 Jan 2020 00:14:27 +0100 Subject: [PATCH] array lists dont have cons/destuctors anymore. RAII is not helpful --- arraylist.hpp | 6 +++--- bucket_allocator.hpp | 3 ++- build.sh | 0 3 files changed, 5 insertions(+), 4 deletions(-) mode change 100755 => 100644 build.sh diff --git a/arraylist.hpp b/arraylist.hpp index 6590b22..44e82ed 100644 --- a/arraylist.hpp +++ b/arraylist.hpp @@ -7,13 +7,13 @@ struct Array_List { int length; int next_index; - Array_List(int initial_capacity = 16) { + void alloc(int initial_capacity = 16) { data = (type*)malloc(initial_capacity * sizeof(type)); next_index = 0; length = initial_capacity; } - ~Array_List() { + void dealloc() { free(data); data = 0; } @@ -52,7 +52,7 @@ struct Array_List { } void reserve(unsigned int count) { - if (next_index+count <= length) { + if (next_index+count <= (unsigned int)length) { length *= 2; data = (type*)realloc(data, length * sizeof(type)); } diff --git a/bucket_allocator.hpp b/bucket_allocator.hpp index e928399..83a9924 100644 --- a/bucket_allocator.hpp +++ b/bucket_allocator.hpp @@ -35,6 +35,7 @@ class Bucket_Allocator { public: Bucket_Allocator(unsigned int bucket_size, unsigned int initial_bucket_count) { + this->free_list.alloc(); this->bucket_size = bucket_size; next_index_in_latest_bucket = 0; next_bucket_index = 0; @@ -48,7 +49,7 @@ public: for (unsigned int i = 0; i <= next_bucket_index; ++i) { free(buckets[i]); } - + this->free_list.dealloc(); free(buckets); } diff --git a/build.sh b/build.sh old mode 100755 new mode 100644