Kaynağa Gözat

added destructors

banana-cakes
FelixBrendel 6 yıl önce
ebeveyn
işleme
43da71f809
5 değiştirilmiş dosya ile 29 ekleme ve 11 silme
  1. +7
    -0
      arraylist.hpp
  2. +13
    -9
      bucket_allocator.hpp
  3. +1
    -1
      build.bat
  4. +7
    -0
      hashmap.hpp
  5. +1
    -1
      test.cpp

+ 7
- 0
arraylist.hpp Dosyayı Görüntüle

@@ -13,6 +13,13 @@ struct Array_List {
length = initial_capacity;
}

~Array_List() {
if (data) {
free(data);
data = nullptr;
}
}

type* begin() {
return data;
}


+ 13
- 9
bucket_allocator.hpp Dosyayı Görüntüle

@@ -48,10 +48,18 @@ public:
}

~Bucket_Allocator() {
for (int i = 0; i < bucket_count; ++i) {
free(buckets[i]);
for (int i = 0; i < latest_bucket-1; ++i) {
for (int j = 0; j < bucket_size; ++j) {
::delete (buckets[i]+j);
}
}
::free(buckets);

for (int i = 0; i < next_index_in_latest_bucket; ++i) {
::delete (buckets[latest_bucket]+i);
}

::delete[] buckets;
free_list.~Array_List();
}

type* allocate(unsigned int amount = 1) {
@@ -84,13 +92,9 @@ public:
}
}

void free(type* obj) {
void free_object(type* obj) {
delete obj;
free_list.append(obj);
}

void reset() {
latest_bucket = 0;
next_index_in_latest_bucket = 0;
next_bucket_index = 0;
}
};

+ 1
- 1
build.bat Dosyayı Görüntüle

@@ -11,7 +11,7 @@ cl^
../test.cpp^
/Fe%exeName% /MP /openmp /W3 /std:c++latest^
/nologo /EHsc /Z7^
/link /incremental /debug:fastlink
/link /incremental

if %errorlevel% == 0 (
echo.


+ 7
- 0
hashmap.hpp Dosyayı Görüntüle

@@ -30,6 +30,13 @@ struct Hash_Map {
data = (HM_Cell*)calloc(initial_capacity, sizeof(HM_Cell));
}

~Hash_Map() {
if (data) {
free(data);
data = nullptr;
}
}

int get_index_of_living_cell_if_it_exists(key_type key, u64 hash_val) {
// int index = hash_val & (current_capacity - 1);
int index = hash_val % current_capacity;


+ 1
- 1
test.cpp Dosyayı Görüntüle

@@ -10,7 +10,7 @@ int main(int argc, char* argv[]) {
*a = 1;
printf("%d\n", *a);

ba.free(a);
ba.free_object(a);

int* b = ba.allocate();
*b = 2;


Yükleniyor…
İptal
Kaydet