📄 mmgro_01.cc
字号:
// file: $isip/class/system/MemoryManager/mmgro_01.cc// version: $Id: mmgro_01.cc,v 1.1 2000/09/20 13:21:43 hamaker Exp $//// isip include files//#include <SysString.h>#include <Console.h>// special isip include files//#define ISIP_INTERNAL_USE_ONLY#include "MemoryManagerOptimize.h" // method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean MemoryManagerOptimize::diagnose(Integral::DEBUG level_a) { // if level_a is DEBUG_NONE, only do a quick test of constructors // and destructors // if (level_a == Integral::NONE) { MemoryManagerOptimize* ptr = new MemoryManagerOptimize(4); delete ptr; return true; } // perform full diagnostic // if (level_a > Integral::BRIEF) { Console::put(L"starting diagnostic"); } // start a memory manager for doubles // MemoryManagerOptimize mgr(sizeof(double)); // test the setDebug method // mgr.setDebug(level_a); if (level_a > Integral::DETAILED) { mgr.debug(L"after initialization"); } // test the get methods // double* ptr0 = (double*)mgr.get(); *ptr0 = 54.0; if (level_a > Integral::DETAILED) { mgr.debug(L"after allocation 0"); } double* ptr1 = (double*)mgr.get(); *ptr1 = 54.1; double* ptr2 = (double*)mgr.get(); *ptr2 = 54.2; double* ptr3 = (double*)mgr.get(); *ptr3 = 54.3; double* ptr4 = (double*)mgr.get(); *ptr4 = 54.4; if (level_a > Integral::DETAILED) { mgr.debug(L"after allocations"); } // test the release methods // mgr.release(ptr0); if ((*ptr1 != 54.1)&&(*ptr2 != 54.2)&&(*ptr3 != 54.3)&&(*ptr4 != 54.4)) { return Error::handle(name(), L"release", Error::TEST, __FILE__, __LINE__); } mgr.release(ptr3); if ((*ptr1 != 54.1)&&(*ptr2 != 54.2)&&(*ptr4 != 54.4)) { return Error::handle(name(), L"release", Error::TEST, __FILE__, __LINE__); } mgr.release(ptr2); if ((*ptr1 != 54.1)&&(*ptr4 != 54.4)) { return Error::handle(name(), L"release", Error::TEST, __FILE__, __LINE__); } mgr.release(ptr4); if (*ptr1 != 54.1) { return Error::handle(name(), L"release", Error::TEST, __FILE__, __LINE__); } mgr.release(ptr1); // let's try to grow several times // mgr.setGrow(3); // test grow and countNodes // long used = 0; long free = 0; if (mgr.grow() || mgr.countNodes(used, free)) { } double* ptr[8198]; for (long i = 0; i < 8198; i++) { ptr[i] = (double*)mgr.get(); *ptr[i] = (double)i; } if (level_a > Integral::DETAILED) { mgr.debug(L"after lots of allocations"); } for (long i = 0; i < 8198; i++) { mgr.release(ptr[i]); } if (level_a > Integral::DETAILED) { mgr.debug(L"after lots of releases"); } // create another memory manager // MemoryManagerOptimize mgr2(sizeof(long)); long* lptr0 = (long*)mgr2.get(); *lptr0 = 54; if (level_a > Integral::DETAILED) { mgr2.debug(L"after allocation 0"); } long* lptr1 = (long*)mgr2.get(); *lptr1 = 55; long* lptr2 = (long*)mgr2.get(); *lptr2 = 56; long* lptr3 = (long*)mgr2.get(); *lptr3 = 57; long* lptr4 = (long*)mgr2.get(); *lptr4 = 58; if (level_a > Integral::DETAILED) { mgr2.debug(L"after allocations"); } mgr2.release(lptr0); mgr2.release(lptr1); mgr2.release(lptr2); mgr2.release(lptr3); mgr2.release(lptr4); // possibly print completion message // if (level_a > Integral::BRIEF) { SysString output(L"\ndiagnostics completed successfully for class "); output.concat(name()); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -