RavEngine
Loading...
Searching...
No Matches
DataStructures.hpp
1#pragma once
2
3#include <plf_list.h>
4#include <plf_colony.h>
5
6namespace RavEngine{
7
8 template<typename T>
9 using LinkedList = plf::list<T>;
10
11 template<typename T>
12 using Colony = plf::colony<T>;
13
14// The stackarray creates a stack-resident array using a runtime-known size.
15// There are no safety checks for overflowing the stack, and overflowing results in undefined behavior.
16// Only use for small sizes. For larger sizes, use the maybestackarray instead
17#if defined __APPLE__ || __STDC_VERSION__ >= 199901L //check for C99
18#define stackarray(name, type, size) type name[size] //prefer C VLA on supported systems
19#else
20#define stackarray(name, type, size) type* name = (type*)alloca(sizeof(type) * size) //warning: alloca may not be supported in the future
21#endif
22
23template<typename T>
25 T* ptr = nullptr;
27 if (ptr != nullptr){
28 delete[] ptr;
29 }
30 }
31};
32
33//The Maybestackarray creates an array using a runtime-known size.
34// It will use stack if it can fit inside a threshold, and use heap memory if it does not.
35// Do not call `delete` on this, the structure will free itself when its scope ends
36#define maybestackarray(name, type, size) \
37type* name;\
38maybestackarray_freer<type> name ## _freer; \
39if (size * sizeof(type) < 1500) name = (type*)alloca(sizeof(type) * size);\
40else { name = new type[size]; name ## _freer.ptr = name; }
41}
Definition plf_colony.h:221
Definition plf_list.h:220
Definition Animation.hpp:6
Definition DataStructures.hpp:24