[Bf-blender-cvs] [6e135618bef] functions-experimental-refactor: use monotonic allocator to allocate functions
Jacques Lucke
noreply at git.blender.org
Tue Nov 5 15:55:17 CET 2019
Commit: 6e135618bef0f37c38fc152322c14d2ac3e666fc
Author: Jacques Lucke
Date: Tue Nov 5 15:54:44 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB6e135618bef0f37c38fc152322c14d2ac3e666fc
use monotonic allocator to allocate functions
===================================================================
M source/blender/blenlib/BLI_resource_collector.h
M source/blender/functions2/intern/vtree_multi_function_network/builder.h
===================================================================
diff --git a/source/blender/blenlib/BLI_resource_collector.h b/source/blender/blenlib/BLI_resource_collector.h
index 5d0e6d5bb3a..5584aafe685 100644
--- a/source/blender/blenlib/BLI_resource_collector.h
+++ b/source/blender/blenlib/BLI_resource_collector.h
@@ -4,6 +4,7 @@
#include "BLI_vector.h"
#include "BLI_utility_mixins.h"
#include "BLI_string_ref.h"
+#include "BLI_monotonic_allocator.h"
namespace BLI {
@@ -16,6 +17,7 @@ class ResourceCollector : NonCopyable {
};
Vector<ResourceData> m_resources;
+ MonotonicAllocator<> m_allocator;
public:
ResourceCollector() = default;
@@ -38,7 +40,7 @@ class ResourceCollector : NonCopyable {
this->add(
resource.release(),
[](void *data) {
- T *typed_data = static_cast<T *>(data);
+ T *typed_data = reinterpret_cast<T *>(data);
delete typed_data;
},
name);
@@ -50,12 +52,17 @@ class ResourceCollector : NonCopyable {
this->add(
resource.release(),
[](void *data) {
- T *typed_data = static_cast<T *>(data);
+ T *typed_data = reinterpret_cast<T *>(data);
typed_data->~T();
},
name);
}
+ void *allocate(uint size, uint alignment)
+ {
+ return m_allocator.allocate(size, alignment);
+ }
+
void add(void *userdata, void (*free)(void *), const char *name)
{
ResourceData data;
diff --git a/source/blender/functions2/intern/vtree_multi_function_network/builder.h b/source/blender/functions2/intern/vtree_multi_function_network/builder.h
index 1167624ffaa..91c3c59148d 100644
--- a/source/blender/functions2/intern/vtree_multi_function_network/builder.h
+++ b/source/blender/functions2/intern/vtree_multi_function_network/builder.h
@@ -49,19 +49,19 @@ class VTreeMFNetworkBuilder : BLI::NonCopyable, BLI::NonMovable {
template<typename T, typename... Args> T &allocate(const char *name, Args &&... args)
{
- std::unique_ptr<T> value = BLI::make_unique<T>(std::forward<Args>(args)...);
- T &value_ref = *value;
- m_resources.add(std::move(value), name);
- return value_ref;
+ void *buffer = m_resources.allocate(sizeof(T), alignof(T));
+ T *value = new (buffer) T(std::forward<Args>(args)...);
+ m_resources.add(BLI::destruct_ptr<T>(value), name);
+ return *value;
}
template<typename T, typename... Args> T &allocate_function(Args &&... args)
{
BLI_STATIC_ASSERT((std::is_base_of<MultiFunction, T>::value), "");
- std::unique_ptr<T> function = BLI::make_unique<T>(std::forward<Args>(args)...);
- T &function_ref = *function;
- m_resources.add(std::move(function), function_ref.name().data());
- return function_ref;
+ void *buffer = m_resources.allocate(sizeof(T), alignof(T));
+ T *fn = new (buffer) T(std::forward<Args>(args)...);
+ m_resources.add(BLI::destruct_ptr<T>(fn), fn->name().data());
+ return *fn;
}
MFDataType try_get_data_type(const VSocket &vsocket) const
More information about the Bf-blender-cvs
mailing list