From c767ef1e3d1d78e50eb1b6d9824b1c8961d68524 Mon Sep 17 00:00:00 2001 From: Max-001 <80035972+Max-001@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:07:18 +0200 Subject: First setup --- mwe/ecs-memory-efficient/inc/ContiguousContainer.h | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 mwe/ecs-memory-efficient/inc/ContiguousContainer.h (limited to 'mwe/ecs-memory-efficient/inc/ContiguousContainer.h') diff --git a/mwe/ecs-memory-efficient/inc/ContiguousContainer.h b/mwe/ecs-memory-efficient/inc/ContiguousContainer.h new file mode 100644 index 0000000..dd0321e --- /dev/null +++ b/mwe/ecs-memory-efficient/inc/ContiguousContainer.h @@ -0,0 +1,34 @@ +#pragma once + +#include // For malloc and free +#include // For placement new +#include // For std::move and std::forward +#include // For std::bad_alloc +#include // For returning references + +template +class ContiguousContainer { +public: + ContiguousContainer(); + ~ContiguousContainer(); + + // Use perfect forwarding for pushBack + template + void pushBack(Args&&... args); + + void popBack(); + T& operator[](size_t index); + size_t getSize() const; + + // Function to return references to all stored objects + std::vector> getAllReferences(); + +private: + T* mData; + size_t mSize; + size_t mCapacity; + + void resize(size_t new_capacity); // Resize function to allocate more space +}; + +#include "ContiguousContainer.hpp" -- cgit v1.2.3