Vector class using arena
This commit is contained in:
@@ -220,6 +220,7 @@
|
|||||||
<CustomBuild Include="src\Graphics\ImGuiRenderer.cpp" />
|
<CustomBuild Include="src\Graphics\ImGuiRenderer.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\Core\Container\Vector.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{ab9c7e88-6c94-4f93-bc2a-7f5284b7d434}</ProjectGuid>
|
<ProjectGuid>{ab9c7e88-6c94-4f93-bc2a-7f5284b7d434}</ProjectGuid>
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ using int64 = int64_t;
|
|||||||
|
|
||||||
using Byte = std::byte;
|
using Byte = std::byte;
|
||||||
|
|
||||||
using size_t = std::size_t;
|
using size_t = std::size_t;
|
||||||
|
using index_t = size_t;
|
||||||
|
|
||||||
struct ByteBuffer
|
struct ByteBuffer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ namespace Juliet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define Restrict __restrict
|
||||||
|
|
||||||
template <class Function>
|
template <class Function>
|
||||||
class DeferredFunction
|
class DeferredFunction
|
||||||
{
|
{
|
||||||
@@ -115,6 +117,13 @@ namespace Juliet
|
|||||||
return (x + alignment - 1) & ~(alignment - 1);
|
return (x + alignment - 1) & ~(alignment - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Swap(auto* Restrict& a, auto* Restrict& b)
|
||||||
|
{
|
||||||
|
auto* temp = a;
|
||||||
|
a = b;
|
||||||
|
b = temp;
|
||||||
|
}
|
||||||
|
|
||||||
// Move to another file dedicated to those
|
// Move to another file dedicated to those
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#define COMPILER_CLANG 1
|
#define COMPILER_CLANG 1
|
||||||
|
|||||||
@@ -107,5 +107,5 @@ namespace Juliet
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
NonNullPtr(T) -> NonNullPtr<T>;
|
NonNullPtr(T*) -> NonNullPtr<T>;
|
||||||
} // namespace Juliet
|
} // namespace Juliet
|
||||||
|
|||||||
@@ -1,9 +1,78 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Core/Common/NonNullPtr.h>
|
||||||
|
#include <Core/Memory/MemoryArena.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <WinSock2.h>
|
||||||
|
|
||||||
namespace Juliet
|
namespace Juliet
|
||||||
{
|
{
|
||||||
|
template <typename Type>
|
||||||
|
struct VectorArena
|
||||||
|
{
|
||||||
|
VectorArena()
|
||||||
|
: First(nullptr)
|
||||||
|
, Count(0)
|
||||||
|
, Stride(sizeof(Type))
|
||||||
|
{
|
||||||
|
Arena = ArenaAllocate();
|
||||||
|
}
|
||||||
|
|
||||||
|
~VectorArena() { ArenaRelease(Arena); }
|
||||||
|
|
||||||
|
void PushBack(Type&& value)
|
||||||
|
{
|
||||||
|
Type* entry = ArenaPushStruct<Type>(Arena);
|
||||||
|
*entry = std::move(value);
|
||||||
|
|
||||||
|
if (Count == 0)
|
||||||
|
{
|
||||||
|
First = entry;
|
||||||
|
}
|
||||||
|
Last = entry;
|
||||||
|
|
||||||
|
++Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveAtFast(index_t index)
|
||||||
|
{
|
||||||
|
Assert(index < Count);
|
||||||
|
Assert(Count > 0);
|
||||||
|
|
||||||
|
Type* baseAdr = First;
|
||||||
|
Type* elementAdr = First + index;
|
||||||
|
|
||||||
|
// Swap Last and element
|
||||||
|
Swap(Last, elementAdr);
|
||||||
|
--Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
ArenaClear(Arena);
|
||||||
|
Count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// C++ Accessors for loop supports and Index based access
|
||||||
|
Type& operator[](size_t index) { return First[index]; }
|
||||||
|
const Type& operator[](size_t index) const { return First[index]; }
|
||||||
|
|
||||||
|
Type* begin() { return First; }
|
||||||
|
Type* end() { return First + Count; }
|
||||||
|
|
||||||
|
const Type* begin() const { return First; }
|
||||||
|
const Type* end() const { return First + Count; }
|
||||||
|
|
||||||
|
size_t Size() const { return Count; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Arena* Arena;
|
||||||
|
Type* First;
|
||||||
|
Type* Last;
|
||||||
|
size_t Count;
|
||||||
|
size_t Stride;
|
||||||
|
};
|
||||||
|
|
||||||
// TODO : Create my own Vector class based on https://github.com/niklas-ourmachinery/bitsquid-foundation/blob/master/collection_types.h
|
// TODO : Create my own Vector class based on https://github.com/niklas-ourmachinery/bitsquid-foundation/blob/master/collection_types.h
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Vector : public std::vector<T>
|
class Vector : public std::vector<T>
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ namespace Juliet
|
|||||||
|
|
||||||
uint64 BasePosition;
|
uint64 BasePosition;
|
||||||
uint64 Position;
|
uint64 Position;
|
||||||
uint64 Capacity;
|
|
||||||
uint64 Alignment;
|
uint64 Alignment;
|
||||||
|
|
||||||
uint64 CommitSize;
|
uint64 CommitSize;
|
||||||
|
|||||||
5
Juliet/src/Core/Container/Vector.cpp
Normal file
5
Juliet/src/Core/Container/Vector.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include <Core/Container/Vector.h>
|
||||||
|
|
||||||
|
namespace Juliet
|
||||||
|
{
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user