[commit] r1591 - in trunk/GME: Common Core

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Wed Oct 5 10:48:30 CDT 2011


Author: ksmyth
Date: Wed Oct  5 10:48:29 2011
New Revision: 1591

Log:
Use forward_list to conserve memory

Modified:
   trunk/GME/Common/CommonCollection.h
   trunk/GME/Core/CoreBinFile.cpp
   trunk/GME/Core/CoreBinFile.h
   trunk/GME/Core/CoreMetaObject.h
   trunk/GME/Core/CoreMetaProject.h
   trunk/GME/Core/CoreObject.cpp
   trunk/GME/Core/CoreObject.h
   trunk/GME/Core/CoreProject.cpp
   trunk/GME/Core/CoreProject.h
   trunk/GME/Core/StdAfx.h

Modified: trunk/GME/Common/CommonCollection.h
==============================================================================
--- trunk/GME/Common/CommonCollection.h	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Common/CommonCollection.h	Wed Oct  5 10:48:29 2011	(r1591)
@@ -243,6 +243,12 @@
 		Fill(col.begin(), col.end());
 	}
 
+	template<class COLLTYPE2>
+	void FillAllNoReserve(COLLTYPE2& col)
+	{
+		Fill(col.begin(), col.end());
+	}
+
 	void Add(OBJTYPE *i)
 	{
 		ASSERT( i != NULL );

Modified: trunk/GME/Core/CoreBinFile.cpp
==============================================================================
--- trunk/GME/Core/CoreBinFile.cpp	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreBinFile.cpp	Wed Oct  5 10:48:29 2011	(r1591)
@@ -1170,8 +1170,8 @@
 
 	CloseObject();
 
-	core::list<objects_iterator>::iterator i = deleted_objects.begin();
-	core::list<objects_iterator>::iterator e = deleted_objects.end();
+	auto i = deleted_objects.begin();
+	auto e = deleted_objects.end();
 	while( i != e )
 	{
 		ASSERT( (*i)->second.deleted );
@@ -1208,8 +1208,8 @@
 		++j;
 	}
 
-	core::list<objects_iterator>::iterator i = deleted_objects.begin();
-	core::list<objects_iterator>::iterator e = deleted_objects.end();
+	auto i = deleted_objects.begin();
+	auto e = deleted_objects.end();
 	while( i != e )
 	{
 		ASSERT( (*i)->second.deleted );

Modified: trunk/GME/Core/CoreBinFile.h
==============================================================================
--- trunk/GME/Core/CoreBinFile.h	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreBinFile.h	Wed Oct  5 10:48:29 2011	(r1591)
@@ -289,8 +289,8 @@
 	typedef maxobjids_type::iterator maxobjids_iterator;
 
 	maxobjids_type maxobjids;
-	core::list<objects_iterator> deleted_objects;
-	core::list<objects_iterator> created_objects;
+	core::forward_list<objects_iterator> deleted_objects;
+	core::forward_list<objects_iterator> created_objects;
 
 	struct resolve_type
 	{
@@ -299,7 +299,7 @@
 		metaobjidpair_type idpair;
 	};
 
-	typedef core::list<resolve_type> resolvelist_type;
+	typedef core::forward_list<resolve_type> resolvelist_type;
 	resolvelist_type resolvelist;
 
 	void InitMaxObjIDs();

Modified: trunk/GME/Core/CoreMetaObject.h
==============================================================================
--- trunk/GME/Core/CoreMetaObject.h	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreMetaObject.h	Wed Oct  5 10:48:29 2011	(r1591)
@@ -44,7 +44,7 @@
 // ------- Properties
 
 public:
-	typedef std::list<CCoreMetaAttribute*> attributes_type;//slist
+	typedef std::forward_list<CCoreMetaAttribute*> attributes_type;
 
 	CCoreMetaProject *project;
 	attributes_type attributes;

Modified: trunk/GME/Core/CoreMetaProject.h
==============================================================================
--- trunk/GME/Core/CoreMetaProject.h	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreMetaProject.h	Wed Oct  5 10:48:29 2011	(r1591)
@@ -49,7 +49,7 @@
 
 public:
 
-	typedef std::list<CCoreMetaObject*> objects_type;//slist
+	typedef std::forward_list<CCoreMetaObject*> objects_type;
 	typedef objects_type::iterator objects_iterator;
 
 	objects_type objects;

Modified: trunk/GME/Core/CoreObject.cpp
==============================================================================
--- trunk/GME/Core/CoreObject.cpp	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreObject.cpp	Wed Oct  5 10:48:29 2011	(r1591)
@@ -89,7 +89,7 @@
 	HRESULT hr = E_NOINTERFACE;
 
 	aggregates_type &aggregates = ((CCoreObject*)pvThis)->aggregates;
-	ASSERT( aggregates.size() >= 0 );
+	ASSERT( aggregates.cbegin() != aggregates.cend() );
 
 	aggregates_iterator i = aggregates.begin();
 	aggregates_iterator e = aggregates.end();
@@ -169,7 +169,8 @@
 		CComObjPtr<COMTYPE> q;
 		CreateComObject(q);
 
-		q->FillAll(attributes);
+		// forward_list doesn't have size(), so we can't reserve
+		q->FillAllNoReserve(attributes);
 		MoveTo(q,p);
 	}
 	COMCATCH(;)
@@ -434,7 +435,8 @@
 	attributes_iterator i = std::find(attributes.begin(), attributes.end(), attribute);
 	ASSERT( i != attributes.end() );
 
-	attributes.erase(i);
+	//attributes.erase(i);
+	attributes.remove(attribute);
 }
 
 template<class Functor, class UnwindFunctor>
@@ -590,8 +592,11 @@
 	std::string metaname;
 	CopyTo(metabstr, metaname);
 
+	attributes_type::size_type size = 0;
+	std::for_each(attributes.begin(), attributes.end(), 
+		[&size](const attributes_type::value_type& e) { size++; });
 	AtlTrace("object_dump metaid=%d metaname=\"%s\" objid=%d, #attrs: %d\n",
-		(int)GetMetaID(), metaname.begin(), (int)objid, attributes.size());
+		(int)GetMetaID(), metaname.begin(), (int)objid, size);
 
 	attributes_iterator i = attributes.begin();
 	attributes_iterator e = attributes.end();

Modified: trunk/GME/Core/CoreObject.h
==============================================================================
--- trunk/GME/Core/CoreObject.h	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreObject.h	Wed Oct  5 10:48:29 2011	(r1591)
@@ -74,11 +74,11 @@
 	CComObjPtr<CCoreMetaObject> metaobject;
 	objid_type objid;
 
-	typedef core::list<CCoreAttribute*> attributes_type;
+	typedef core::forward_list<CCoreAttribute*> attributes_type;
 	typedef attributes_type::iterator attributes_iterator;
 	attributes_type attributes;
 
-	typedef core::list< CComObjPtr<IUnknown> > aggregates_type;
+	typedef core::forward_list< CComObjPtr<IUnknown> > aggregates_type;
 	typedef aggregates_type::iterator aggregates_iterator;
 	aggregates_type aggregates;
 

Modified: trunk/GME/Core/CoreProject.cpp
==============================================================================
--- trunk/GME/Core/CoreProject.cpp	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreProject.cpp	Wed Oct  5 10:48:29 2011	(r1591)
@@ -888,7 +888,10 @@
 	i = finaltr_items.begin();
 	ASSERT( e == finaltr_items.end() );
 #ifdef _DEBUG
-	int finaltr_count = finaltr_items.size(); 
+	// int finaltr_count = finaltr_items.size();
+	finaltr_items_type::size_type finaltr_count = 0;
+	std::for_each(finaltr_items.begin(), finaltr_items.end(), 
+		[&finaltr_count](const finaltr_items_type::value_type& e) { finaltr_count++; });
 #endif
 	while( i != e )
 	{

Modified: trunk/GME/Core/CoreProject.h
==============================================================================
--- trunk/GME/Core/CoreProject.h	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/CoreProject.h	Wed Oct  5 10:48:29 2011	(r1591)
@@ -21,7 +21,7 @@
 // --------------------------- typedefs
 
 typedef CCoreTransactionItem *transaction_item_type;
-typedef core::list<transaction_item_type> transaction_items_type;
+typedef core::forward_list<transaction_item_type> transaction_items_type;
 typedef transaction_items_type::iterator transaction_items_iterator;
 
 typedef struct transaction_type
@@ -34,7 +34,7 @@
 typedef transactions_type::iterator transactions_iterator;
 
 typedef CCoreFinalTrItem *finaltr_item_type;
-typedef core::list<finaltr_item_type> finaltr_items_type;
+typedef core::forward_list<finaltr_item_type> finaltr_items_type;
 typedef finaltr_items_type::iterator finaltr_items_iterator;
 
 typedef CCoreUndoItem *undo_item_type;

Modified: trunk/GME/Core/StdAfx.h
==============================================================================
--- trunk/GME/Core/StdAfx.h	Wed Oct  5 10:48:10 2011	(r1590)
+++ trunk/GME/Core/StdAfx.h	Wed Oct  5 10:48:29 2011	(r1591)
@@ -24,6 +24,7 @@
 #include "EASTL/hash_set.h"
 #else
 #include <hash_set>
+#include <forward_list>
 #endif
 
 #include <hash_map>
@@ -38,6 +39,7 @@
 	using stdext::hash_set;
 	using stdext::hash_map;
 	using std::list;
+	using std::forward_list;
 	using std::pair;
 #endif
 }


More information about the gme-commit mailing list