[Bf-blender-cvs] [3a87096f244] functions: allocate attributes arrays in AttributeArraysCore
Jacques Lucke
noreply at git.blender.org
Fri Jun 21 16:56:40 CEST 2019
Commit: 3a87096f24485e5d6e30a690e8d22f031b545e07
Author: Jacques Lucke
Date: Fri Jun 21 16:48:19 2019 +0200
Branches: functions
https://developer.blender.org/rB3a87096f24485e5d6e30a690e8d22f031b545e07
allocate attributes arrays in AttributeArraysCore
===================================================================
M source/blender/simulations/bparticles/attributes.cpp
M source/blender/simulations/bparticles/attributes.hpp
M source/blender/simulations/bparticles/particles_container.cpp
M source/blender/simulations/bparticles/particles_container.hpp
===================================================================
diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index e77bd2916fb..416be9b0247 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -22,13 +22,19 @@ AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
m_types.append_n_times(AttributeType::Float3, m_float3_attributes.size());
}
-SmallVector<void *> AttributesInfo::allocate_separate_arrays(uint size) const
+AttributeArraysCore::AttributeArraysCore(AttributesInfo &info, uint size)
+ : m_info(info), m_size(size)
{
- SmallVector<void *> pointers;
- for (AttributeType type : m_types) {
- pointers.append(MEM_malloc_arrayN(size, size_of_attribute_type(type), __func__));
+ for (AttributeType type : info.types()) {
+ m_arrays.append(MEM_malloc_arrayN(size, size_of_attribute_type(type), __func__));
+ }
+}
+
+AttributeArraysCore::~AttributeArraysCore()
+{
+ for (void *ptr : m_arrays) {
+ MEM_freeN(ptr);
}
- return pointers;
}
void JoinedAttributeArrays::set_elements(uint index, void *data)
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 3a6717ea0db..5fbefc2afa4 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -69,6 +69,11 @@ class AttributesInfo {
return m_types[index];
}
+ ArrayRef<AttributeType> types() const
+ {
+ return m_types;
+ }
+
uint attribute_index(StringRef name) const
{
int index = m_indices.index(name.to_std_string());
@@ -95,8 +100,6 @@ class AttributesInfo {
{
return &a == &b;
}
-
- SmallVector<void *> allocate_separate_arrays(uint size) const;
};
class AttributeArrays;
@@ -108,9 +111,8 @@ class AttributeArraysCore {
uint m_size = 0;
public:
- AttributeArraysCore() = default;
-
- AttributeArraysCore(AttributesInfo &info, ArrayRef<void *> arrays, uint size);
+ AttributeArraysCore(AttributesInfo &info, uint size);
+ ~AttributeArraysCore();
AttributesInfo &info();
void *get_ptr(uint index);
@@ -174,13 +176,6 @@ class JoinedAttributeArrays {
/* Attribute Arrays Core
*****************************************/
-inline AttributeArraysCore::AttributeArraysCore(AttributesInfo &info,
- ArrayRef<void *> arrays,
- uint size)
- : m_info(info), m_arrays(arrays.to_small_vector()), m_size(size)
-{
-}
-
inline AttributesInfo &AttributeArraysCore::info()
{
return m_info;
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index 2af961a2da6..c5b8a3c4c13 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -4,15 +4,13 @@ namespace BParticles {
ParticlesBlock::ParticlesBlock(ParticlesContainer &container)
: m_container(container),
- m_arrays(m_container.attributes(),
- m_container.attributes().allocate_separate_arrays(container.block_size()),
- container.block_size()),
+ m_arrays(m_container.attributes(), container.block_size()),
m_active_amount(0)
{
}
-ParticlesContainer::ParticlesContainer(AttributesInfo &attributes, uint block_size)
- : m_attributes(attributes), m_block_size(block_size)
+ParticlesContainer::ParticlesContainer(AttributesInfo attributes, uint block_size)
+ : m_attributes(std::move(attributes)), m_block_size(block_size)
{
}
@@ -39,9 +37,6 @@ void ParticlesContainer::release_block(ParticlesBlock *block)
BLI_assert(m_blocks.contains(block));
BLI_assert(&block->container() == this);
- for (void *buffer : block->arrays_core().pointers()) {
- MEM_freeN(buffer);
- }
m_blocks.remove(block);
delete block;
}
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 43ce91d5335..9e49d2dfafa 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -29,7 +29,7 @@ class ParticlesContainer {
uint m_block_size;
public:
- ParticlesContainer(AttributesInfo &attributes, uint block_size);
+ ParticlesContainer(AttributesInfo attributes, uint block_size);
~ParticlesContainer();
More information about the Bf-blender-cvs
mailing list