From 41de0eaa1adecfbb721cc7361b7af05ae69249ac Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Tue, 25 Aug 2009 14:01:10 +0000 Subject: [PATCH] remove moveable mem --- libsrc/general/moveablemem.cpp | 272 --------------------------------- libsrc/general/moveablemem.hpp | 108 ------------- 2 files changed, 380 deletions(-) delete mode 100644 libsrc/general/moveablemem.cpp delete mode 100644 libsrc/general/moveablemem.hpp diff --git a/libsrc/general/moveablemem.cpp b/libsrc/general/moveablemem.cpp deleted file mode 100644 index 51f538be..00000000 --- a/libsrc/general/moveablemem.cpp +++ /dev/null @@ -1,272 +0,0 @@ -#include -#include - -#include -using namespace std; -namespace netgen -{ - -#ifdef OLD - NgMutex mem_mutex; - - size_t BaseMoveableMem::totalsize = 0; // 500000000; - size_t BaseMoveableMem::used = 0; - char * BaseMoveableMem::largeblock = 0; - - BaseMoveableMem * BaseMoveableMem::first = NULL; - BaseMoveableMem * BaseMoveableMem::last = NULL; - - - BaseMoveableMem :: BaseMoveableMem (size_t s) - { - // Print (); - - prev = last; - next = 0; - - if (last) last->next = this; - last = this; - if (!first) first = this; - - size = 0; - - if (prev) - pos = prev->pos + prev->size; - else - pos = 0; - - ptr = 0; - name = NULL; - - if (s) Alloc(s); - } - - BaseMoveableMem :: ~BaseMoveableMem () throw() - { - Free(); - - if (next) next->prev = prev; - else last = prev; - if (prev) prev->next = next; - else first = next; - - if(name != NULL) - { - delete [] name; - name = NULL; - } - } - - void BaseMoveableMem :: SetName (const char * aname) - { - if(name != NULL) - { - delete [] name; - name = NULL; - } - if (aname) - { - name = new char[strlen(aname)+1]; - strcpy (name, aname); - } - } - - - void BaseMoveableMem :: Alloc (size_t s) - { - if (totalsize == 0) - { - size = s; - //ptr = (char*) malloc(s); - ptr = new char[s]; - - if (!ptr) - { - cerr << "BaseynamicMem, cannot allocate " << s << " bytes" << endl; - Print (); - throw ("BaseDynamicMem::Alloc: out of memory"); - } - - return; - } - - - used += s - size; - - size_t r = s % 8; - if (r) s += 8-r; - if (prev) - pos = prev->pos + prev->size; - else - pos = 0; - size = s; - - if (next) - { - NgLock lock(mem_mutex); - lock.Lock(); - try - { - next->MoveTo (pos+size); - } - catch (NgException e) - { - lock.UnLock(); - throw NgException ("MoveableMem overflow"); - } - lock.UnLock(); - } - - if (size) - { - if (!largeblock) - { - cout << "moveable memory: allocate large block of " - << totalsize / 1048576 << " MB" << endl; - // largeblock = new char[totalsize]; - // largeblock = (char*)malloc (totalsize); - largeblock = new char[totalsize]; - } - ptr = largeblock+pos; - - if (pos + size > totalsize) - throw NgException ("MoveableMem overflow"); - } - else - ptr = 0; - } - - void BaseMoveableMem :: ReAlloc (size_t s) - { - if (totalsize == 0) - { - if (size == s) return; - - char * old = ptr; - ptr = new char[s]; - - if (!ptr) - { - cerr << "BaseynamicMem, cannot Reallocate " << s << " bytes" << endl; - Print (); - throw ("BaseDynamicMem::Alloc: out of memory"); - } - - - - memmove (ptr, old, (s < size) ? s : size); - //free (old); - delete [] old; - size = s; - return; - } - - Alloc (s); - } - - void BaseMoveableMem :: MoveTo (size_t newpos) - { - // cout << "move block, oldpos = " << pos << "; newpos = " << newpos - // << ", size = " << size << endl; - static size_t move = 0; - - if (newpos + size > totalsize) - throw NgException ("MoveableMem overflow"); - if (newpos > pos) - { - if (next) next->MoveTo (newpos+size); - memmove (largeblock+newpos, largeblock+pos, size); - move += size; - } - else if (newpos < pos) - { - // cout << "move down: " << size << endl; - memmove (largeblock+newpos, largeblock+pos, size); - if (next) next->MoveTo (newpos+size); - move += size; - } - pos = newpos; - ptr = largeblock+pos; - // cout << "total move: " << move << endl; - } - - void BaseMoveableMem :: Free () throw() - { - if (totalsize == 0) - { - //free (ptr); - delete [] ptr; - ptr = 0; - return; - } - - /* - cout << "free block, pos = " << pos << "size = " << size << endl; - cout << "before: " << endl; - Print(); - */ - used -= size; - if (next) - { - NgLock lock(mem_mutex); - lock.Lock(); - next->MoveTo (pos); - lock.UnLock(); - } - - size = 0; - ptr = 0; - // pos = 0; - } - - void BaseMoveableMem :: Swap (BaseMoveableMem & m2) throw() - { - size_t hi; - // BaseMoveableMem * hp; - char * cp; - hi = size; size = m2.size; m2.size = hi; - hi = pos; pos = m2.pos; m2.pos = hi; - /* - hp = prev; prev = m2.prev; m2.prev = hp; - hp = next; next = m2.next; m2.next = hp; - */ - cp = ptr; ptr = m2.ptr; m2.ptr = cp; - cp = name; name = m2.name; m2.name = cp; - } - - - void BaseMoveableMem :: Print () - { - cout << "****************** Moveable Mem Report ****************" << endl; - BaseMoveableMem * p = first; - long int mem = 0; - int cnt = 0; - while (p) - { - mem += long(p->size); - cnt++; - - cout << setw(10) << p->size << " Bytes"; - cout << ", pos = " << p->pos; - cout << ", addr = " << (void*)p->ptr; - if (p->name) - cout << " in block " << p->name; - cout << endl; - - p = p->next; - } - - if (mem > 100000000) - cout << "memory in moveable arena: " << mem/1048576 << " MB" << endl; - else if (mem > 100000) - cout << "memory in moveable arena: " << mem/1024 << " kB" << endl; - else - cout << "memory in moveable arena: " << mem << " Bytes" << endl; - cout << "number of blocks: " << cnt << endl; - - cout << " used = " << used << endl; - // cout << "******************************************************" << endl; - } -#endif - -} diff --git a/libsrc/general/moveablemem.hpp b/libsrc/general/moveablemem.hpp deleted file mode 100644 index 956b973d..00000000 --- a/libsrc/general/moveablemem.hpp +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef FILE_MOVEABLEMEM -#define FILE_MOVEABLEMEM - -/**************************************************************************/ -/* File: moveablemem.hpp */ -/* Author: Joachim Schoeberl */ -/* Date: 12. Feb. 2003 */ -/**************************************************************************/ - -namespace netgen -{ -#ifdef OLD - - extern NgMutex mem_mutex; - - - -class BaseMoveableMem -{ -public: - static size_t totalsize; - static size_t used; - -private: - static char * largeblock; - static BaseMoveableMem *first, *last; - - BaseMoveableMem *prev, *next; - size_t size, pos; - char * ptr; - char * name; - -protected: - BaseMoveableMem (size_t s = 0); - ~BaseMoveableMem () throw(); - void Alloc (size_t s); - void ReAlloc (size_t s); - void MoveTo (size_t newpos); - void Free () throw(); - char * Ptr() { return ptr; } - char * Ptr() const { return ptr; } - void Swap (BaseMoveableMem & m2) throw(); -public: - void SetName (const char * aname); - static void Print (); - - friend class BaseDynamicMem; -}; - - - - -template -class MoveableMem : public BaseMoveableMem -{ -public: - MoveableMem (size_t s = 0) - : BaseMoveableMem (sizeof(T) * s) - { - ; - } - void Alloc (size_t s) - { - BaseMoveableMem::Alloc (sizeof(T) * s); - } - void ReAlloc (size_t s) - { - BaseMoveableMem::ReAlloc (sizeof(T) * s); - } - void Free () - { - BaseMoveableMem::Free (); - } - - const T * Ptr() const - { - return reinterpret_cast (BaseMoveableMem::Ptr()); - } - - T * Ptr() - { - return reinterpret_cast (BaseMoveableMem::Ptr()); - } - - operator T* () const - { - return reinterpret_cast (BaseMoveableMem::Ptr()); - } - - operator T* () - { - return reinterpret_cast (BaseMoveableMem::Ptr()); - } - - void Swap (MoveableMem & m2) - { - BaseMoveableMem::Swap (m2); - } -protected: - MoveableMem (const MoveableMem & m) { ; } - MoveableMem & operator= (const MoveableMem & m) { ; } -}; - -#endif - -} - -#endif