Hello all:
As part of our on-going effort to track down some OpenSG memory usage,
I tried to write a function that would:
1) Count up the number of allocated field containers (from the field
container factory)
2) Print out a nice little report about how many of each class type
have been allocated
The goal was to see if there were some object types that keep growing.
Then hopefully this could point to a section of the code that we
could look at to fix the leak.
Anyway, I wrote the function below, but it didn't work. It comes back
thinking the type of all fc's is "FieldContainer". I suspect
type-pruning, but I don't see the error. Can anyone see my mistake?
-Allen
#include <sstream>
typedef std::map< OSG::UInt32, OSG::UInt64> fc_type_to_count_map_t;
std::string getAllocatedFieldContainerDescription()
{
// Build up the list
OSG::UInt64 num_allocated_fcs(0);
fc_type_to_count_map_t type_count_map; // Map from type id to type count
OSG::FieldContainerFactoryBase* fcf = OSG::FieldContainerFactory::the();
OSG::TypeFactoryBase* type_factory = OSG::TypeFactory::the();
const OSG::FieldContainerFactoryBase::ContainerStore&
fcs(fcf->getContainerStore());
for(OSG::UInt64 i=0; i<fcs.size(); i++)
{
OSG::FieldContainerPtr fcp(fcs[i]);
if (fcp != OSG::NullFC)
{
OSG::UInt32 type_id = fcp->getClassTypeId();
std::string class_name = fcp->getClassType().getCName();
//std::cout << "type id: " << type_id << " class:" <<
class_name << std::endl; <-- Always "FieldContainer"
num_allocated_fcs += 1;
if(type_count_map.find(type_id) != type_count_map.end())
{ type_count_map[type_id] += 1; }
else
{ type_count_map[type_id] = 1; }
}
}
std::stringstream stream; // Stream to output description data
stream << "Num fc's allocated: " << num_allocated_fcs << "/" <<
fcf->getNumContainers() << std::endl;
for(fc_type_to_count_map_t::iterator i = type_count_map.begin(); i
!= type_count_map.end(); i++)
{
OSG::UInt32 type_id = (*i).first;
OSG::UInt64 type_count = (*i).second;
OSG::TypeBase* type = type_factory->findType(type_id);
std::string type_name(type->getCName());
if(type != NULL)
{
stream << " " << type_name << ": " << type_count << std::endl;
}
else
{
stream << " type-id:" << type_id << ": " << type_count << std::endl;
}
}
return stream.str(); // Return the description
}
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users