added destructors

This commit is contained in:
FelixBrendel
2019-10-30 00:36:44 +01:00
parent a20539587c
commit 43da71f809
5 changed files with 29 additions and 11 deletions
+7
View File
@@ -13,6 +13,13 @@ struct Array_List {
length = initial_capacity;
}
~Array_List() {
if (data) {
free(data);
data = nullptr;
}
}
type* begin() {
return data;
}
+13 -9
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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;