[MOAB-dev] r1525 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Mon Jan 14 15:46:39 CST 2008
Author: kraftche
Date: 2008-01-14 15:46:39 -0600 (Mon, 14 Jan 2008)
New Revision: 1525
Modified:
MOAB/trunk/SequenceData.cpp
MOAB/trunk/SequenceData.hpp
MOAB/trunk/SequenceManager.cpp
MOAB/trunk/SequenceManager.hpp
MOAB/trunk/SparseTagCollections.cpp
MOAB/trunk/VarLenTag.hpp
Log:
Add code for releasing variable-length tag storage
Modified: MOAB/trunk/SequenceData.cpp
===================================================================
--- MOAB/trunk/SequenceData.cpp 2008-01-14 21:42:04 UTC (rev 1524)
+++ MOAB/trunk/SequenceData.cpp 2008-01-14 21:46:39 UTC (rev 1525)
@@ -1,6 +1,7 @@
#include "SequenceData.hpp"
#include "TagServer.hpp"
#include "MBSysUtil.hpp"
+#include "VarLenTag.hpp"
#include <assert.h>
SequenceData::~SequenceData()
@@ -150,15 +151,22 @@
}
}
-void SequenceData::release_tag_data()
+void SequenceData::release_tag_data( const int* tag_sizes, int num_tag_sizes )
{
+ assert( num_tag_sizes >= numTagData );
for (unsigned i = 1; i <= numTagData; ++i)
- release_tag_data( i );
+ release_tag_data( i, tag_sizes[i] );
}
-void SequenceData::release_tag_data( MBTagId tag_num )
+void SequenceData::release_tag_data( MBTagId tag_num, int tag_size )
{
if (tag_num < numTagData) {
+ if (tag_size == MB_VARIABLE_LENGTH && arraySet[tag_num+1]) {
+ VarLenTag* iter = reinterpret_cast<VarLenTag*>(arraySet[tag_num+1]);
+ VarLenTag* const end = iter + size();
+ for (; iter != end; ++iter)
+ iter->clear();
+ }
free( arraySet[tag_num+1] );
arraySet[tag_num+1] = 0;
}
Modified: MOAB/trunk/SequenceData.hpp
===================================================================
--- MOAB/trunk/SequenceData.hpp 2008-01-14 21:42:04 UTC (rev 1524)
+++ MOAB/trunk/SequenceData.hpp 2008-01-14 21:46:39 UTC (rev 1525)
@@ -121,9 +121,9 @@
void move_tag_data( SequenceData* destination, TagServer* tag_server );
/**\brief Free all tag data arrays */
- void release_tag_data();
+ void release_tag_data(const int* tag_sizes, int num_tag_sizes);
/**\brief Free specified tag data array */
- void release_tag_data( MBTagId tag_num );
+ void release_tag_data( MBTagId tag_num, int tag_size );
protected:
Modified: MOAB/trunk/SequenceManager.cpp
===================================================================
--- MOAB/trunk/SequenceManager.cpp 2008-01-14 21:42:04 UTC (rev 1524)
+++ MOAB/trunk/SequenceManager.cpp 2008-01-14 21:46:39 UTC (rev 1525)
@@ -21,8 +21,21 @@
MBEntityID SequenceManager::default_poly_sequence_size( int conn_len )
{ return std::max( DEFAULT_POLY_SEQUENCE_SIZE / conn_len, (MBEntityID)1 ); }
+SequenceManager::~SequenceManager()
+{
+ // release variable-length tag data
+ for (unsigned i = 0; i < tagSizes.size(); ++i)
+ if (tagSizes[i] == MB_VARIABLE_LENGTH)
+ release_tag( i );
+}
+
void SequenceManager::clear()
{
+ // release variable-length tag data
+ for (unsigned i = 0; i < tagSizes.size(); ++i)
+ if (tagSizes[i] == MB_VARIABLE_LENGTH)
+ release_tag( i );
+
// destroy all TypeSequenceManager instances
for (MBEntityType t = MBVERTEX; t < MBMAXTYPE; ++t)
typeData[t].~TypeSequenceManager();
@@ -674,14 +687,14 @@
for (MBEntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
TypeSequenceManager& seqs = entity_map(t);
for (TypeSequenceManager::iterator i = seqs.begin(); i != seqs.end(); ++i)
- (*i)->data()->release_tag_data();
+ (*i)->data()->release_tag_data( &tagSizes[0], tagSizes.size() );
}
}
-MBErrorCode SequenceManager::reserve_tag_id( unsigned size, MBTagId tag_id )
+MBErrorCode SequenceManager::reserve_tag_id( int size, MBTagId tag_id )
{
- if (!size)
- return MB_FAILURE;
+ if (size < 1) //&& size != MB_VARIABLE_LENGTH)
+ return MB_INVALID_SIZE;
if (tag_id >= tagSizes.size())
tagSizes.resize( tag_id+1, 0 );
if (tagSizes[tag_id])
@@ -699,14 +712,15 @@
for (MBEntityType t = MBVERTEX; t <= MBENTITYSET; ++t) {
TypeSequenceManager& seqs = entity_map(t);
for (TypeSequenceManager::iterator i = seqs.begin(); i != seqs.end(); ++i)
- (*i)->data()->release_tag_data(tag_id);
+ (*i)->data()->release_tag_data(tag_id, tagSizes[tag_id]);
}
return MB_SUCCESS;
}
MBErrorCode SequenceManager::remove_tag_data( MBTagId tag_id,
MBEntityHandle handle,
- const void* default_tag_value )
+ const void* default_tag_value,
+ int default_value_size )
{
if (tag_id >= tagSizes.size() || !tagSizes[tag_id])
return MB_TAG_NOT_FOUND;
@@ -722,7 +736,14 @@
char* tag_data = reinterpret_cast<char*>(tag_array) +
tagSizes[tag_id] * (handle - seq->data()->start_handle());
- if (default_tag_value)
+ if (tagSizes[tag_id] == MB_VARIABLE_LENGTH) {
+ VarLenTag* vdata = reinterpret_cast<VarLenTag*>(tag_data);
+ if (default_tag_value)
+ vdata->set( default_tag_value, default_value_size );
+ else
+ vdata->clear();
+ }
+ else if (default_tag_value)
memcpy( tag_data, default_tag_value, tagSizes[tag_id] );
else
memset( tag_data, 0, tagSizes[tag_id] );
Modified: MOAB/trunk/SequenceManager.hpp
===================================================================
--- MOAB/trunk/SequenceManager.hpp 2008-01-14 21:42:04 UTC (rev 1524)
+++ MOAB/trunk/SequenceManager.hpp 2008-01-14 21:46:39 UTC (rev 1525)
@@ -15,7 +15,9 @@
SequenceManager( const MBHandleUtils& handle_utils )
: handleUtils(handle_utils)
{}
-
+
+ ~SequenceManager();
+
/** Delete all contained data */
void clear();
@@ -122,12 +124,13 @@
void reset_tag_data();
- MBErrorCode reserve_tag_id( unsigned tag_size, MBTagId tag_id );
+ MBErrorCode reserve_tag_id( int tag_size, MBTagId tag_id );
MBErrorCode release_tag( MBTagId tag_id );
MBErrorCode remove_tag_data( MBTagId tag_id,
MBEntityHandle handle,
- const void* default_tag_value );
+ const void* default_tag_value,
+ int default_value_size = 0 );
MBErrorCode set_tag_data( MBTagId tag_id,
MBEntityHandle handle,
const void* value,
@@ -215,7 +218,7 @@
const MBHandleUtils handleUtils;
TypeSequenceManager typeData[MBMAXTYPE];
- std::vector<unsigned> tagSizes;
+ std::vector<int> tagSizes;
};
#endif
Modified: MOAB/trunk/SparseTagCollections.cpp
===================================================================
--- MOAB/trunk/SparseTagCollections.cpp 2008-01-14 21:42:04 UTC (rev 1524)
+++ MOAB/trunk/SparseTagCollections.cpp 2008-01-14 21:46:39 UTC (rev 1525)
@@ -258,6 +258,8 @@
for(tag_iterator = mData.begin(); tag_iterator != mData.end(); ++tag_iterator)
{
tag_data = tag_iterator->second;
+ if (mDataSize == MB_VARIABLE_LENGTH)
+ reinterpret_cast<VarLenTag*>(tag_data)->clear();
if(tag_data != NULL)
mAllocator.destroy(tag_data);
}
@@ -310,6 +312,8 @@
if(iterator != mData.end())
{
+ if (mDataSize == MB_VARIABLE_LENGTH)
+ reinterpret_cast<VarLenTag*>(iterator->second)->clear();
mAllocator.destroy(iterator->second);
mData.erase(iterator);
return MB_SUCCESS;
Modified: MOAB/trunk/VarLenTag.hpp
===================================================================
--- MOAB/trunk/VarLenTag.hpp 2008-01-14 21:42:04 UTC (rev 1524)
+++ MOAB/trunk/VarLenTag.hpp 2008-01-14 21:46:39 UTC (rev 1525)
@@ -147,6 +147,9 @@
inline void clear();
+ inline void set( const void* data, unsigned size )
+ { memcpy( resize(size), data, size ); }
+
};
inline unsigned char* VarLenTag::resize( unsigned s )
More information about the moab-dev
mailing list