[MOAB-dev] r1472 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Fri Dec 14 14:16:15 CST 2007
Author: kraftche
Date: 2007-12-14 14:16:15 -0600 (Fri, 14 Dec 2007)
New Revision: 1472
Modified:
MOAB/trunk/SequenceManager.cpp
MOAB/trunk/SequenceManager.hpp
MOAB/trunk/TypeSequenceManager.cpp
MOAB/trunk/TypeSequenceManager.hpp
Log:
Consolidate small allocation requests from file readers.
Modified: MOAB/trunk/SequenceManager.cpp
===================================================================
--- MOAB/trunk/SequenceManager.cpp 2007-12-14 20:07:07 UTC (rev 1471)
+++ MOAB/trunk/SequenceManager.cpp 2007-12-14 20:16:15 UTC (rev 1472)
@@ -10,12 +10,16 @@
#include <assert.h>
#include <new>
+#include <algorithm>
-const int DEFAULT_VERTEX_SEQUENCE_SIZE = 4096;
-const int DEFAULT_ELEMENT_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
-const int DEFAULT_POLY_SEQUENCE_SIZE = 4 * DEFAULT_ELEMENT_SEQUENCE_SIZE;
-const int DEFAULT_MESHSET_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
+const MBEntityID DEFAULT_VERTEX_SEQUENCE_SIZE = 4096;
+const MBEntityID DEFAULT_ELEMENT_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
+const MBEntityID DEFAULT_POLY_SEQUENCE_SIZE = 4 * DEFAULT_ELEMENT_SEQUENCE_SIZE;
+const MBEntityID DEFAULT_MESHSET_SEQUENCE_SIZE = DEFAULT_VERTEX_SEQUENCE_SIZE;
+MBEntityID SequenceManager::default_poly_sequence_size( int conn_len )
+ { return std::max( DEFAULT_POLY_SEQUENCE_SIZE / conn_len, (MBEntityID)1 ); }
+
void SequenceManager::clear()
{
// destroy all TypeSequenceManager instances
@@ -162,9 +166,7 @@
SequenceData* seq_data = 0;
unsigned size = DEFAULT_ELEMENT_SEQUENCE_SIZE;
if (type == MBPOLYGON || type == MBPOLYHEDRON) {
- size = DEFAULT_POLY_SEQUENCE_SIZE / conn_len;
- if (!size)
- size = 1;
+ size = default_poly_sequence_size( conn_len );
}
handle = typeData[type].find_free_sequence( size, start, end, seq_data, conn_len );
@@ -361,6 +363,27 @@
return handle;
}
+
+MBEntityID SequenceManager::new_sequence_size( MBEntityHandle start,
+ MBEntityID requested_size,
+ MBEntityID default_size ) const
+{
+ if (requested_size >= default_size)
+ return requested_size;
+
+ MBEntityHandle last = typeData[TYPE_FROM_HANDLE(start)].last_free_handle( start );
+ if (!last) {
+ assert( false );
+ return 0;
+ }
+
+ MBEntityID available_size = last - start + 1;
+ if (default_size < available_size)
+ return default_size;
+ else
+ return available_size;
+}
+
MBErrorCode
SequenceManager::create_entity_sequence( MBEntityType type,
MBEntityID count,
@@ -390,7 +413,8 @@
if (data)
sequence = new VertexSequence( handle, count, data );
else
- sequence = new VertexSequence( handle, count, count );
+ sequence = new VertexSequence( handle, count,
+ new_sequence_size( handle, count, DEFAULT_VERTEX_SEQUENCE_SIZE ) );
break;
@@ -402,7 +426,8 @@
if (data)
sequence = new PolyElementSeq( handle, count, size, data );
else
- sequence = new PolyElementSeq( handle, count, size, count );
+ sequence = new PolyElementSeq( handle, count, size,
+ new_sequence_size( handle, count, default_poly_sequence_size(size) ) );
break;
@@ -413,7 +438,8 @@
if (data)
sequence = new UnstructuredElemSeq( handle, count, size, data );
else
- sequence = new UnstructuredElemSeq( handle, count, size, count );
+ sequence = new UnstructuredElemSeq( handle, count, size,
+ new_sequence_size( handle, count, DEFAULT_ELEMENT_SEQUENCE_SIZE ) );
break;
}
Modified: MOAB/trunk/SequenceManager.hpp
===================================================================
--- MOAB/trunk/SequenceManager.hpp 2007-12-14 20:07:07 UTC (rev 1471)
+++ MOAB/trunk/SequenceManager.hpp 2007-12-14 20:16:15 UTC (rev 1472)
@@ -167,7 +167,14 @@
unsigned long& total,
unsigned long& per_entity ) const;
+ /**\brief Get default size of POLYGON and POLYHEDRON SequenceData */
+ static MBEntityID default_poly_sequence_size( int entity_connectivity_length );
+ /**\brief Size to allocate for new SquenceData */
+ MBEntityID new_sequence_size( MBEntityHandle start_handle,
+ MBEntityID reqested_size,
+ MBEntityID default_size ) const;
+
private:
/**\brief Utility function for allocate_mesh_set (and similar)
Modified: MOAB/trunk/TypeSequenceManager.cpp
===================================================================
--- MOAB/trunk/TypeSequenceManager.cpp 2007-12-14 20:07:07 UTC (rev 1471)
+++ MOAB/trunk/TypeSequenceManager.cpp 2007-12-14 20:16:15 UTC (rev 1472)
@@ -547,6 +547,18 @@
return 0;
}
+MBEntityHandle TypeSequenceManager::last_free_handle( MBEntityHandle after_this ) const
+{
+ int junk;
+ const_iterator it = lower_bound( after_this );
+ if (it == end())
+ return CREATE_HANDLE( TYPE_FROM_HANDLE(after_this), MB_END_ID, junk );
+ else if ((*it)->start_handle() > after_this)
+ return (*it)->start_handle() - 1;
+ else
+ return 0;
+}
+
MBErrorCode TypeSequenceManager::check_valid_handles( MBEntityHandle first,
MBEntityHandle last ) const
{
Modified: MOAB/trunk/TypeSequenceManager.hpp
===================================================================
--- MOAB/trunk/TypeSequenceManager.hpp 2007-12-14 20:07:07 UTC (rev 1471)
+++ MOAB/trunk/TypeSequenceManager.hpp 2007-12-14 20:16:15 UTC (rev 1472)
@@ -303,6 +303,8 @@
MBEntityHandle& block_end,
int values_per_ent = 0 );
+ MBEntityHandle last_free_handle( MBEntityHandle after_this ) const;
+
/**\brief Notify that sequence was prepended to
*
* Notify of sequence modifications so we can check if
More information about the moab-dev
mailing list