[Bf-blender-cvs] [23a1209] hair_system: Distinguish nominal and allocated size of hair volume attributes.
Lukas Tönne
noreply at git.blender.org
Sun Aug 24 18:55:00 CEST 2014
Commit: 23a12096305d6328dd4ba0c01962f3586ab04e5c
Author: Lukas Tönne
Date: Sun Aug 24 13:54:33 2014 +0200
Branches: hair_system
https://developer.blender.org/rB23a12096305d6328dd4ba0c01962f3586ab04e5c
Distinguish nominal and allocated size of hair volume attributes.
This allows keeping extra memory around for later use instead of freeing
every time the attribute needs to be resized (compare to std::vector).
===================================================================
M source/blender/hair/intern/HAIR_volume.h
===================================================================
diff --git a/source/blender/hair/intern/HAIR_volume.h b/source/blender/hair/intern/HAIR_volume.h
index ec3fd71..525beba 100644
--- a/source/blender/hair/intern/HAIR_volume.h
+++ b/source/blender/hair/intern/HAIR_volume.h
@@ -40,6 +40,7 @@ struct VolumeAttribute {
VolumeAttribute()
{
m_data = NULL;
+ m_alloc_size = 0;
m_size = 0;
}
@@ -60,26 +61,44 @@ struct VolumeAttribute {
void resize(int size)
{
- free();
- alloc(size);
+ if (size > m_alloc_size) {
+ free();
+ alloc(size);
+ }
+ else {
+ m_size = size;
+ }
+ }
+
+ void shrink_to_fit()
+ {
+ if (m_size < m_alloc_size) {
+ free();
+ alloc(m_size);
+ }
}
protected:
void alloc(int size)
{
- m_data = (T*)MEM_mallocN(sizeof(T) * size, "Hair Volume Attribute");
+ m_data = size > 0 ? (T*)MEM_mallocN(sizeof(T) * size, "Hair Volume Attribute") : NULL;
+ m_alloc_size = size;
m_size = size;
}
void free()
{
- if (m_data)
+ if (m_data) {
MEM_freeN(m_data);
+ m_data = NULL;
+ }
+ m_alloc_size = 0;
+ m_size = 0;
}
private:
T *m_data;
- int m_size;
+ int m_size, m_alloc_size;
};
typedef VolumeAttribute<float> VolumeAttributeFloat;
More information about the Bf-blender-cvs
mailing list