'memory usage' bug fix

This commit is contained in:
Joachim Schoeberl 2009-01-28 21:32:30 +00:00
parent 103fe76a1d
commit b087ac2f72
2 changed files with 227 additions and 234 deletions

View File

@ -1,11 +1,5 @@
#include <iostream>
#include <iomanip>
#ifdef SSE
#include <emmintrin.h>
#endif
#include <myadt.hpp> #include <myadt.hpp>
using namespace std; using namespace std;
namespace netgen namespace netgen
@ -176,7 +170,7 @@ namespace netgen
BaseMoveableMem * pm = BaseMoveableMem::first; BaseMoveableMem * pm = BaseMoveableMem::first;
while (pm) while (pm)
{ {
long unsigned hptr = (long unsigned) p->ptr; long unsigned hptr = (long unsigned) pm->ptr;
// uintptr_t hptr = reinterpret_cast<uintptr_t>(pm->ptr); // uintptr_t hptr = reinterpret_cast<uintptr_t>(pm->ptr);
hptr /= (1024*1024); hptr /= (1024*1024);

View File

@ -12,13 +12,12 @@ namespace netgen
size_t BaseMoveableMem::used = 0; size_t BaseMoveableMem::used = 0;
char * BaseMoveableMem::largeblock = 0; char * BaseMoveableMem::largeblock = 0;
BaseMoveableMem * BaseMoveableMem::first = 0; BaseMoveableMem * BaseMoveableMem::first = NULL;
BaseMoveableMem * BaseMoveableMem::last = 0; BaseMoveableMem * BaseMoveableMem::last = NULL;
BaseMoveableMem :: BaseMoveableMem (size_t s) BaseMoveableMem :: BaseMoveableMem (size_t s)
{ {
// cout << "Construct object begin" << endl;
// Print (); // Print ();
prev = last; prev = last;
@ -39,10 +38,10 @@ namespace netgen
name = NULL; name = NULL;
if (s) Alloc(s); if (s) Alloc(s);
} }
BaseMoveableMem :: ~BaseMoveableMem () throw() BaseMoveableMem :: ~BaseMoveableMem () throw()
{ {
Free(); Free();
if (next) next->prev = prev; if (next) next->prev = prev;
@ -55,10 +54,10 @@ BaseMoveableMem :: ~BaseMoveableMem () throw()
delete [] name; delete [] name;
name = NULL; name = NULL;
} }
} }
void BaseMoveableMem :: SetName (const char * aname) void BaseMoveableMem :: SetName (const char * aname)
{ {
if(name != NULL) if(name != NULL)
{ {
delete [] name; delete [] name;
@ -69,11 +68,11 @@ void BaseMoveableMem :: SetName (const char * aname)
name = new char[strlen(aname)+1]; name = new char[strlen(aname)+1];
strcpy (name, aname); strcpy (name, aname);
} }
} }
void BaseMoveableMem :: Alloc (size_t s) void BaseMoveableMem :: Alloc (size_t s)
{ {
if (totalsize == 0) if (totalsize == 0)
{ {
size = s; size = s;
@ -134,10 +133,10 @@ void BaseMoveableMem :: Alloc (size_t s)
} }
else else
ptr = 0; ptr = 0;
} }
void BaseMoveableMem :: ReAlloc (size_t s) void BaseMoveableMem :: ReAlloc (size_t s)
{ {
if (totalsize == 0) if (totalsize == 0)
{ {
if (size == s) return; if (size == s) return;
@ -162,10 +161,10 @@ void BaseMoveableMem :: ReAlloc (size_t s)
} }
Alloc (s); Alloc (s);
} }
void BaseMoveableMem :: MoveTo (size_t newpos) void BaseMoveableMem :: MoveTo (size_t newpos)
{ {
// cout << "move block, oldpos = " << pos << "; newpos = " << newpos // cout << "move block, oldpos = " << pos << "; newpos = " << newpos
// << ", size = " << size << endl; // << ", size = " << size << endl;
static size_t move = 0; static size_t move = 0;
@ -188,10 +187,10 @@ void BaseMoveableMem :: MoveTo (size_t newpos)
pos = newpos; pos = newpos;
ptr = largeblock+pos; ptr = largeblock+pos;
// cout << "total move: " << move << endl; // cout << "total move: " << move << endl;
} }
void BaseMoveableMem :: Free () throw() void BaseMoveableMem :: Free () throw()
{ {
if (totalsize == 0) if (totalsize == 0)
{ {
//free (ptr); //free (ptr);
@ -217,10 +216,10 @@ void BaseMoveableMem :: Free () throw()
size = 0; size = 0;
ptr = 0; ptr = 0;
// pos = 0; // pos = 0;
} }
void BaseMoveableMem :: Swap (BaseMoveableMem & m2) throw() void BaseMoveableMem :: Swap (BaseMoveableMem & m2) throw()
{ {
size_t hi; size_t hi;
// BaseMoveableMem * hp; // BaseMoveableMem * hp;
char * cp; char * cp;
@ -232,11 +231,11 @@ void BaseMoveableMem :: Swap (BaseMoveableMem & m2) throw()
*/ */
cp = ptr; ptr = m2.ptr; m2.ptr = cp; cp = ptr; ptr = m2.ptr; m2.ptr = cp;
cp = name; name = m2.name; m2.name = cp; cp = name; name = m2.name; m2.name = cp;
} }
void BaseMoveableMem :: Print () void BaseMoveableMem :: Print ()
{ {
cout << "****************** Moveable Mem Report ****************" << endl; cout << "****************** Moveable Mem Report ****************" << endl;
BaseMoveableMem * p = first; BaseMoveableMem * p = first;
long int mem = 0; long int mem = 0;
@ -266,6 +265,6 @@ void BaseMoveableMem :: Print ()
cout << " used = " << used << endl; cout << " used = " << used << endl;
// cout << "******************************************************" << endl; // cout << "******************************************************" << endl;
} }
} }