Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename StackAllocator to ArenaAllocator #463

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@

namespace chowdsp
{
/** A simple stack allocator */
class StackAllocator
/** A simple arena allocator */
class ArenaAllocator
{
public:
StackAllocator() = default;
ArenaAllocator() = default;

StackAllocator (const StackAllocator&) = delete;
StackAllocator& operator= (const StackAllocator&) = delete;
/** Constructs the arena with an initial allocated size. */
explicit ArenaAllocator (size_t size_in_bytes)
{
reset (size_in_bytes);
}

ArenaAllocator (const ArenaAllocator&) = delete;
ArenaAllocator& operator= (const ArenaAllocator&) = delete;

StackAllocator (StackAllocator&&) noexcept = default;
StackAllocator& operator= (StackAllocator&&) noexcept = default;
ArenaAllocator (ArenaAllocator&&) noexcept = default;
ArenaAllocator& operator= (ArenaAllocator&&) noexcept = default;

/** Re-allocates the internal buffer with a given number of bytes */
void reset (size_t new_size_bytes)
Expand Down Expand Up @@ -64,20 +70,20 @@ class StackAllocator
* Once the frame goes out of scope, the allocator will be reset
* to whatever it's state was at the beginning of the frame.
*/
struct StackAllocatorFrame
struct ArenaAllocatorFrame
{
explicit StackAllocatorFrame (StackAllocator& allocator)
explicit ArenaAllocatorFrame (ArenaAllocator& allocator)
: alloc (allocator),
bytes_used_at_start (alloc.bytes_used)
{
}

~StackAllocatorFrame()
~ArenaAllocatorFrame()
{
alloc.bytes_used = bytes_used_at_start;
}

StackAllocator& alloc;
ArenaAllocator& alloc;
const size_t bytes_used_at_start;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BEGIN_JUCE_MODULE_DECLARATION
#include "Structures/chowdsp_OptionalPointer.h"
#include "Structures/chowdsp_RawObject.h"
#include "Structures/chowdsp_SmallVector.h"
#include "Structures/chowdsp_StackAllocator.h"
#include "Structures/chowdsp_ArenaAllocator.h"
#include "Structures/chowdsp_StringLiteral.h"

#include "Helpers/chowdsp_ArrayHelpers.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <CatchUtils.h>
#include <chowdsp_data_structures/chowdsp_data_structures.h>

TEST_CASE ("Stack Allocator Test", "[common][data-structures]")
TEST_CASE ("Arena Allocator Test", "[common][data-structures]")
{
chowdsp::StackAllocator allocator;
allocator.reset (150);
chowdsp::ArenaAllocator allocator { 150 };

// allocate doubles
{
Expand All @@ -22,7 +21,7 @@ TEST_CASE ("Stack Allocator Test", "[common][data-structures]")

// allocate with stack frame
{
chowdsp::StackAllocator::StackAllocatorFrame frame { allocator };
chowdsp::ArenaAllocator::ArenaAllocatorFrame frame { allocator };
auto* some_chars = allocator.allocate<char> (30);
juce::ignoreUnused (some_chars);
REQUIRE (allocator.get_bytes_used() == 150);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target_sources(chowdsp_data_structures_test
LocalPointerTest.cpp
OptionalPointerTest.cpp
SmallVectorTest.cpp
StackAllocatorTest.cpp
ArenaAllocatorTest.cpp
StringLiteralTest.cpp
TupleHelpersTest.cpp
VectorHelpersTest.cpp
Expand Down
Loading