Procházet zdrojové kódy

array lists dont have cons/destuctors anymore. RAII is not helpful

banana-cakes
FelixBrendel před 6 roky
rodič
revize
7b128b33c9
3 změnil soubory, kde provedl 5 přidání a 4 odebrání
  1. +3
    -3
      arraylist.hpp
  2. +2
    -1
      bucket_allocator.hpp
  3. +0
    -0
     

+ 3
- 3
arraylist.hpp Zobrazit soubor

@@ -7,13 +7,13 @@ struct Array_List {
int length; int length;
int next_index; int next_index;


Array_List(int initial_capacity = 16) {
void alloc(int initial_capacity = 16) {
data = (type*)malloc(initial_capacity * sizeof(type)); data = (type*)malloc(initial_capacity * sizeof(type));
next_index = 0; next_index = 0;
length = initial_capacity; length = initial_capacity;
} }


~Array_List() {
void dealloc() {
free(data); free(data);
data = 0; data = 0;
} }
@@ -52,7 +52,7 @@ struct Array_List {
} }


void reserve(unsigned int count) { void reserve(unsigned int count) {
if (next_index+count <= length) {
if (next_index+count <= (unsigned int)length) {
length *= 2; length *= 2;
data = (type*)realloc(data, length * sizeof(type)); data = (type*)realloc(data, length * sizeof(type));
} }


+ 2
- 1
bucket_allocator.hpp Zobrazit soubor

@@ -35,6 +35,7 @@ class Bucket_Allocator {


public: public:
Bucket_Allocator(unsigned int bucket_size, unsigned int initial_bucket_count) { Bucket_Allocator(unsigned int bucket_size, unsigned int initial_bucket_count) {
this->free_list.alloc();
this->bucket_size = bucket_size; this->bucket_size = bucket_size;
next_index_in_latest_bucket = 0; next_index_in_latest_bucket = 0;
next_bucket_index = 0; next_bucket_index = 0;
@@ -48,7 +49,7 @@ public:
for (unsigned int i = 0; i <= next_bucket_index; ++i) { for (unsigned int i = 0; i <= next_bucket_index; ++i) {
free(buckets[i]); free(buckets[i]);
} }
this->free_list.dealloc();
free(buckets); free(buckets);
} }




+ 0
- 0
Zobrazit soubor


Načítá se…
Zrušit
Uložit