From c81cb64416217df2de4032c818914fea0691e92c Mon Sep 17 00:00:00 2001 From: AndreaCatania Date: Sat, 14 Aug 2021 09:00:58 +0200 Subject: [PATCH] Add the possibility to initialize the classes allocated with the PagedAllocator It uses the (`const T &&... p_args`) forward reference, to avoid copying the memory in case it's an rvalue, or pass a reference in case it's an lvalue. This is an example: ```c++ PagedAllocator box_allocator; btShapeBox* box = box_allocator.alloc( btVector3(1.0, 1.0, 1.0) ); ``` --- core/templates/paged_allocator.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/templates/paged_allocator.h b/core/templates/paged_allocator.h index 481289309fd..dfc885c6eb0 100644 --- a/core/templates/paged_allocator.h +++ b/core/templates/paged_allocator.h @@ -50,7 +50,8 @@ class PagedAllocator { SpinLock spin_lock; public: - T *alloc() { + template + T *alloc(const Args &&...p_args) { if (thread_safe) { spin_lock.lock(); } @@ -75,7 +76,7 @@ public: if (thread_safe) { spin_lock.unlock(); } - memnew_placement(alloc, T); + memnew_placement(alloc, T(p_args...)); return alloc; }