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<btShapeBox> box_allocator; btShapeBox* box = box_allocator.alloc( btVector3(1.0, 1.0, 1.0) ); ```
This commit is contained in:
parent
f32c042f3e
commit
c81cb64416
1 changed files with 3 additions and 2 deletions
|
@ -50,7 +50,8 @@ class PagedAllocator {
|
||||||
SpinLock spin_lock;
|
SpinLock spin_lock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T *alloc() {
|
template <class... Args>
|
||||||
|
T *alloc(const Args &&...p_args) {
|
||||||
if (thread_safe) {
|
if (thread_safe) {
|
||||||
spin_lock.lock();
|
spin_lock.lock();
|
||||||
}
|
}
|
||||||
|
@ -75,7 +76,7 @@ public:
|
||||||
if (thread_safe) {
|
if (thread_safe) {
|
||||||
spin_lock.unlock();
|
spin_lock.unlock();
|
||||||
}
|
}
|
||||||
memnew_placement(alloc, T);
|
memnew_placement(alloc, T(p_args...));
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue