From bbbb6c3143530873a54b7f70d04f1be4ee5612db Mon Sep 17 00:00:00 2001 From: jatin Date: Wed, 27 Mar 2024 22:50:52 -0700 Subject: [PATCH] Book-keeping for manual destruction --- .../Structures/chowdsp_SmallVector.h | 7 +++++++ .../chowdsp_data_structures/chowdsp_data_structures.h | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/common/chowdsp_data_structures/Structures/chowdsp_SmallVector.h b/modules/common/chowdsp_data_structures/Structures/chowdsp_SmallVector.h index 03ab154a6..761b25774 100644 --- a/modules/common/chowdsp_data_structures/Structures/chowdsp_SmallVector.h +++ b/modules/common/chowdsp_data_structures/Structures/chowdsp_SmallVector.h @@ -261,8 +261,12 @@ class SmallVector { if (usingArray) { + internal_needs_destruction = make_array (true); for (size_t i = 0; i < internal_array_size_used; ++i) + { internal_array[i].~T(); + internal_needs_destruction[i] = false; + } internal_array_size_used = 0; } internal_vector.clear(); @@ -447,6 +451,8 @@ class SmallVector { if (internal_array_size_used + 1 <= head_size) { + if (internal_needs_destruction[internal_array_size_used]) + internal_array[internal_array_size_used].~T(); new (&internal_array[internal_array_size_used]) T (args...); internal_array_size_used++; return internal_array[internal_array_size_used - 1]; @@ -520,6 +526,7 @@ class SmallVector std::array internal_array {}; size_t internal_array_size_used = 0; + std::array internal_needs_destruction = make_array (true); std::vector internal_vector {}; diff --git a/modules/common/chowdsp_data_structures/chowdsp_data_structures.h b/modules/common/chowdsp_data_structures/chowdsp_data_structures.h index 48cdb93c4..c983e5e4d 100644 --- a/modules/common/chowdsp_data_structures/chowdsp_data_structures.h +++ b/modules/common/chowdsp_data_structures/chowdsp_data_structures.h @@ -24,6 +24,11 @@ BEGIN_JUCE_MODULE_DECLARATION #include "third_party/short_alloc.h" +#include "Helpers/chowdsp_ArrayHelpers.h" +#include "Helpers/chowdsp_TupleHelpers.h" +#include "Helpers/chowdsp_VectorHelpers.h" +#include "Helpers/chowdsp_Iterators.h" + #include "Structures/chowdsp_DoubleBuffer.h" #include "Structures/chowdsp_DestructiblePointer.h" #include "Structures/chowdsp_LocalPointer.h" @@ -32,11 +37,6 @@ BEGIN_JUCE_MODULE_DECLARATION #include "Structures/chowdsp_SmallVector.h" #include "Structures/chowdsp_StringLiteral.h" -#include "Helpers/chowdsp_ArrayHelpers.h" -#include "Helpers/chowdsp_TupleHelpers.h" -#include "Helpers/chowdsp_VectorHelpers.h" -#include "Helpers/chowdsp_Iterators.h" - #include "Allocators/chowdsp_ArenaAllocator.h" #include "Allocators/chowdsp_ChainedArenaAllocator.h"