Skip to content

Commit

Permalink
Book-keeping for manual destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Mar 28, 2024
1 parent c6a1841 commit bbbb6c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,12 @@ class SmallVector
{
if (usingArray)
{
internal_needs_destruction = make_array<bool, head_size> (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();
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -520,6 +526,7 @@ class SmallVector

std::array<T, head_size> internal_array {};
size_t internal_array_size_used = 0;
std::array<bool, head_size> internal_needs_destruction = make_array<bool, head_size> (true);

std::vector<T> internal_vector {};

Expand Down
10 changes: 5 additions & 5 deletions modules/common/chowdsp_data_structures/chowdsp_data_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down

0 comments on commit bbbb6c3

Please sign in to comment.