libER 0.1.4.2
ELDEN RING API library
Loading...
Searching...
No Matches
from_allocator.hpp
Go to the documentation of this file.
1
8#pragma once
9
10#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL > 0
11#error "_ITERATOR_DEBUG_LEVEL" must be defined as "0" for STL containers to be compatible with the ELDEN RING ABI.
12#endif
13
14#include <detail/preprocessor.hpp>
15
16#include <cstddef>
17#include <cstdint>
18#include <utility>
19
20namespace from {
21namespace DLKR {
38public:
39 virtual ~DLAllocator() = default;
40
46 virtual int get_allocator_id() = 0;
47
54 virtual int _unk0x10() {
55 return -1;
56 }
57
65 virtual int& get_heap_flags(int& flags) = 0;
66
72 virtual size_t get_heap_capacity() = 0;
73
79 virtual size_t get_heap_size() = 0;
80
86 virtual size_t get_heap_backing_capacity() = 0;
87
94 virtual size_t get_heap_allocation_count() = 0;
95
102 virtual size_t msize(void* p) = 0;
103
112 virtual void* allocate(size_t cb) = 0;
113
124 virtual void* allocate_aligned(size_t cb, size_t alignment) = 0;
125
136 virtual void* reallocate(void* p, size_t cb) = 0;
137
149 virtual void* reallocate_aligned(void* p, size_t cb, size_t alignment) = 0;
150
156 virtual void deallocate(void* p) = 0;
157
163 virtual void _unk0x70() {}
164
174 virtual void* allocate2(size_t cb) {
175 return this->allocate(cb);
176 }
177
189 virtual void* allocate2_aligned(size_t cb, size_t alignment) {
190 return this->allocate_aligned(cb, alignment);
191 }
192
204 virtual void* reallocate2(void* p, size_t cb) {
205 return this->reallocate(p, cb);
206 }
207
220 virtual void* reallocate2_aligned(void* p, size_t cb, size_t alignment) {
221 return this->reallocate_aligned(p, cb, alignment);
222 }
223
230 virtual void deallocate2(void* p) {
231 this->deallocate(p);
232 }
233
238 virtual bool _unk0xA0() {
239 return false;
240 }
241
246 virtual bool check_owned(void* p) = 0;
247
252 virtual bool _unk0xB0(std::nullptr_t) {
253 return false;
254 }
255
260 virtual void lock() = 0;
261
266 virtual void unlock() = 0;
267
276 virtual void* get_block(void* p) = 0;
277};
278
285LIBERAPI DLAllocator& get_dlallocator_of(const void* p) noexcept;
286
296LIBERAPI DLAllocator& get_base_allocator() noexcept;
297} // namespace DLKR
298
307template <typename T>
310 using alloc_type = std::conditional_t<std::is_same_v<T, void>, char, T>;
311
312 base_type* base;
313
314public:
319 using value_type = T;
320
325 using size_type = size_t;
326
331 using difference_type = ptrdiff_t;
332
338
344 using is_always_equal = std::false_type;
345
350 allocator() noexcept : base(&DLKR::get_base_allocator()) {}
351
359 allocator(const allocator& other) noexcept : base(other.base) {}
360
369 template <typename U>
370 allocator(const allocator<U>& other) noexcept : base(other.base) {}
371
377 explicit allocator(base_type* allocator_base) noexcept
378 : base(allocator_base) {}
379
386 [[nodiscard]] T* allocate(size_type n) {
387 return reinterpret_cast<T*>(this->base->allocate_aligned(
388 n * sizeof(alloc_type), alignof(alloc_type)));
389 }
390
397 void deallocate(T* p, size_type n = 0) {
398 this->base->deallocate(static_cast<void*>(p));
399 }
400
405 template <typename T1, typename T2>
406 friend bool operator==(const allocator<T1>& lhs,
407 const allocator<T2>& rhs) noexcept;
408};
409
414template <typename T1, typename T2>
415bool operator==(const allocator<T1>& lhs, const allocator<T2>& rhs) noexcept {
416 return lhs.base == rhs.base;
417}
418
425template <typename T>
427 return from::allocator<T>(
428 &DLKR::get_dlallocator_of(static_cast<const void*>(p)));
429}
430} // namespace from
Common ELDEN RING allocator interface.
Definition from_allocator.hpp:37
virtual size_t get_heap_backing_capacity()=0
The remaining capacity of the backing heap.
virtual size_t get_heap_allocation_count()=0
Total number of objects that have been allocated on the allocator's heap.
virtual int & get_heap_flags(int &flags)=0
Allocator and heap compatibility flags.
virtual void * get_block(void *p)=0
Get the memory block that this memory belongs to.
virtual void * reallocate2_aligned(void *p, size_t cb, size_t alignment)
Reallocate an aligned memory block with a new size. Use the second allocator if it is bound,...
Definition from_allocator.hpp:220
virtual size_t get_heap_size()=0
How many bytes out of the total capacity are allocated.
virtual void * reallocate(void *p, size_t cb)=0
Reallocate a memory block with a new size.
virtual void * allocate2_aligned(size_t cb, size_t alignment)
Allocate a block of at least this many bytes with a given alignment. Use the second allocator if it i...
Definition from_allocator.hpp:189
virtual void _unk0x70()
Unknown method, isn't supported by any class that implements DLKR::DLAllocator.
Definition from_allocator.hpp:163
virtual void * allocate_aligned(size_t cb, size_t alignment)=0
Allocate a block of at least this many bytes with a given alignment.
virtual void * reallocate2(void *p, size_t cb)
Reallocate a memory block with a new size. Use the second allocator if it is bound,...
Definition from_allocator.hpp:204
virtual bool check_owned(void *p)=0
Does the pointed to memory block belong to this allocator?
virtual int get_allocator_id()=0
Unique allocator id sometimes used for comparing allocators.
virtual size_t get_heap_capacity()=0
The total capacity of the heap, in bytes.
virtual void * allocate(size_t cb)=0
Allocate a block of at least this many bytes.
virtual int _unk0x10()
Unknown function which is defined in the interface, never overriden or used.
Definition from_allocator.hpp:54
virtual void deallocate(void *p)=0
Free previously allocated memory.
virtual void deallocate2(void *p)
Free previously allocated memory. Use the second allocator if it is bound, first if not.
Definition from_allocator.hpp:230
virtual void lock()=0
Lock the allocator's mutex (if present and accessible).
virtual size_t msize(void *p)=0
Check how big a given memory block is.
virtual bool _unk0xB0(std::nullptr_t)
Seemingly unused.
Definition from_allocator.hpp:252
virtual void * reallocate_aligned(void *p, size_t cb, size_t alignment)=0
Reallocate an aligned memory block with a new size.
virtual void unlock()=0
Unlock the allocator's mutex (if present and accessible).
virtual void * allocate2(size_t cb)
Allocate a block of at least this many bytes. Use the second allocator if it is bound,...
Definition from_allocator.hpp:174
virtual bool _unk0xA0()
Unknown method, seemingly unused.
Definition from_allocator.hpp:238
The main libER stand-in for ER allocator proxies.
Definition from_allocator.hpp:308
allocator(const allocator< U > &other) noexcept
Allocator copy constructor.
Definition from_allocator.hpp:370
T value_type
The allocated value type.
Definition from_allocator.hpp:319
std::false_type is_always_equal
This allocator may proxy different stateful allocators.
Definition from_allocator.hpp:344
allocator() noexcept
Default allocator constructor.
Definition from_allocator.hpp:350
T * allocate(size_type n)
Allocate n instances of uninitialized memory for T.
Definition from_allocator.hpp:386
std::true_type propagate_on_container_move_assignment
This allocator is move assigned along with the contents.
Definition from_allocator.hpp:337
void deallocate(T *p, size_type n=0)
Deallocate previously allocated memory.
Definition from_allocator.hpp:397
ptrdiff_t difference_type
Memory difference type.
Definition from_allocator.hpp:331
size_t size_type
Memory size type.
Definition from_allocator.hpp:325
allocator(base_type *allocator_base) noexcept
Wrap an existing DLKR::DLAllocator.
Definition from_allocator.hpp:377
friend bool operator==(const allocator< T1 > &lhs, const allocator< T2 > &rhs) noexcept
Allocator equality comparison.
Definition from_allocator.hpp:415
allocator(const allocator &other) noexcept
Allocator copy constructor.
Definition from_allocator.hpp:359
LIBERAPI DLAllocator & get_base_allocator() noexcept
Get a compatible ELDEN RING base allocator.
from::allocator< T > get_allocator_of(const T *p) noexcept
Get the allocator of an object allocated by ELDEN RING.
Definition from_allocator.hpp:426
LIBERAPI DLAllocator & get_dlallocator_of(const void *p) noexcept
Get the allocator of memory allocated by ELDEN RING.