299 extern void _Safenew(
const char*
file,
int line,
int flag = 0);
300 extern void _Safenewfill(
void* pv,
size_t size,
char fill);
302 const char cDebugAlloc =
'A';
303 const char cDebugFree =
'F';
305 #ifdef DEBUG_MEMMANAGER
308 #define SAFENEW_(pnt, item, memman) \
311 ASSERT(sizeof(item)); \
314 _Safenew(__FILE__, __LINE__); \
316 (memman).add((void*)(pnt), sizeof(item)); \
320 #define SAFENEWWITHCONSTRUCTOR_(pnt, item, constructor, memman) \
323 ASSERT(sizeof(item)); \
324 (pnt) = new constructor; \
326 _Safenew(__FILE__, __LINE__); \
328 (memman).add((void*)(pnt), sizeof(item)); \
334 #define SAFENEWARR_(pnt, item, sz, memman) \
337 ASSERT(sizeof(item)); \
339 (pnt) = new item[sz]; \
341 _Safenew(__FILE__, __LINE__, 1); \
343 (memman).add((void*)(pnt), sizeof(item)*(sz), 1); \
344 _Safenewfill((void*)pnt, sizeof(item)*(sz), cDebugAlloc); \
348 #define SAFENEWARRNOFILL_(pnt, item, sz, memman) \
351 ASSERT(sizeof(item)); \
353 (pnt) = new item[sz]; \
355 _Safenew(__FILE__, __LINE__, 1); \
357 (memman).add((void*)(pnt), sizeof(item)*(sz), 1); \
360 #define SAFESTRDUP_(pnt, src, memman) \
364 unsigned int l = strlen((src))+1; \
365 (pnt) = new char[l]; \
367 _Safenew(__FILE__, __LINE__, 1); \
369 strcpy((char *)(pnt), (src)); \
370 (memman).add((void*)(pnt), l, 1); \
376 #ifndef DEBUG_MEMMANAGER_DELETEBUTKEEPLOG
378 #ifndef DEBUG_MEMMANAGER_DELETEBUTNOTRELEASE
380 #define SAFEDELETE_(pnt, memman) \
383 (memman).remove((void*)(pnt)); \
388 #define SAFEDELETEARR_(pnt, memman) \
391 (memman).remove((void*)(pnt), 1); \
396 #define SAFEDELETEANDFILLARR_(pnt, memman) \
399 (memman).remove((void*)(pnt), 1, 1); \
408 #ifdef DEBUG_MEMMANAGER_DELETEBUTKEEPLOG
410 #define SAFEDELETE_(pnt, memman) \
413 (memman).removeButKeepLog((void*)(pnt)); \
418 #define SAFEDELETEARR_(pnt, memman) \
421 (memman).removeButKeepLog((void*)(pnt), 1); \
426 #define SAFEDELETEANDFILLARR_(pnt, memman) \
429 (memman).removeButKeepLog((void*)(pnt), 1); \
436 #ifdef DEBUG_MEMMANAGER_DELETEBUTNOTRELEASE
438 #define SAFEDELETE_(pnt, memman) \
441 (memman).removeButNotRelease((void*)(pnt)); \
446 #define SAFEDELETEARR_(pnt, memman) \
449 (memman).removeButNotRelease((void*)(pnt), 1); \
454 #define SAFEDELETEANDFILLARR_(pnt, memman) \
457 (memman).removeButNotRelease((void*)(pnt), 1); \
480 stMemBlock(
void* _pv = NULL,
size_t _size = 0, eStatus _eSt = UNKNOWN,
482 : pv(_pv), size(_size), eSt(_eSt), fArr(_fArr), fRef(_fRef) {
489 friend ostream&
operator << (ostream& rout,
const clMemMan& rm);
505 stList(stMemBlock stIn) : stMB(stIn), pstNext(NULL) {
513 stList* pstFindElem(
const void* pvToFind)
const;
514 stList* pstFindPrev(
const void* pvToFindPrev)
const;
522 void _remove(
const void* pvToRemove, eRemoveMode eMode,
flag fArr,
526 clMemMan(
char* sName = NULL);
529 flag fIsBlock(
const void* pvBlock,
size_t sizeBlock = 1)
const;
530 flag fIsPointerToBlock(
const void* pvBlock)
const;
531 flag fIsValid(
const void* pvValid,
size_t sizeValid = 1)
const;
532 size_t sizeOfBlock(
const void* pvSizeOf)
const;
533 flag fIsArray(
const void* pvIsArray)
const;
534 eStatus eBlockStatus(
const void* pvBStatus)
const;
536 void ClearRefs(
void);
537 void PutRef(
const void* pvRef);
538 flag fIsRefd(
const void* pvIsRefd)
const;
539 ostream& DumpRef(ostream& rout)
const;
541 void add(
const void* pvIn,
size_t sizeIn,
flag fArr = 0);
542 inline void remove(
const void* pvToRemove,
flag fArr = 0,
flag fFill = 0) {
543 _remove(pvToRemove, RELEASE, fArr, fFill);
546 inline void removeButNotRelease(
const void* pvToRemove,
flag fArr = 0,
flag fFill = 0) {
547 _remove(pvToRemove, DELBUTNOTRELEASE, fArr, fFill);
550 inline void removeButKeepLog(
const void* pvToRemove,
flag fArr = 0,
flag fFill = 0) {
551 _remove(pvToRemove, DELBUTKEEPLOG, fArr, fFill);
558 extern ostream&
operator << (ostream& rout,
const clMemMan& rm);
563 #define SAFENEW_(pnt, item, memman) \
566 ASSERT(sizeof(item)); \
569 _Safenew(__FILE__, __LINE__); \
574 #define SAFENEWWITHCONSTRUCTOR_(pnt, item, constructor, memman) \
577 ASSERT(sizeof(item)); \
578 (pnt) = new constructor; \
580 _Safenew(__FILE__, __LINE__); \
588 #define SAFENEWARR_(pnt, item, sz, memman) \
591 ASSERT(sizeof(item)); \
593 (pnt) = new item[sz]; \
595 _Safenew(__FILE__, __LINE__, 1); \
597 _Safenewfill(pnt, sizeof(item)*(sz), cDebugAlloc); \
601 #define SAFENEWARRNOFILL_(pnt, item, sz, memman) \
604 ASSERT(sizeof(item)); \
606 (pnt) = new item[sz]; \
608 _Safenew(__FILE__, __LINE__, 1); \
612 #define SAFESTRDUP_(pnt, src, memman) \
616 unsigned int l = strlen((src))+1; \
617 (pnt) = new char[l]; \
619 _Safenew(__FILE__, __LINE__, 1); \
621 strcpy((char *)(pnt), (src)); \
627 #define SAFEDELETE_(pnt, memman) \
629 ASSERT((pnt) != 0); \
634 #define SAFEDELETEARR_(pnt, memman) \
636 ASSERT((pnt) != 0); \
641 #define SAFEDELETEANDFILLARR_(pnt, memman) \
643 ASSERT((pnt) != 0); \
653 #define SAFENEW_(pnt, item, memman) \
657 #define SAFENEWWITHCONSTRUCTOR_(pnt, item, constructor, memman) \
658 (pnt) = new constructor
660 #define SAFENEWARR_(pnt, item, sz, memman) \
663 #define SAFENEWARRNOFILL_(pnt, item, sz, memman) \
666 #define SAFESTRDUP_(pnt, src, memman) \
668 unsigned int l = strlen((src))+1; \
669 (pnt) = new char[l]; \
670 strcpy((char *)(pnt), (src)); \
673 #define SAFEDELETE_(pnt, memman) \
679 #define SAFEDELETEARR_(pnt, memman) \
685 #define SAFEDELETEANDFILLARR_(pnt, memman) \
691 #define defaultMemoryManager 0
695 #define SAFENEW(pnt, item) \
696 SAFENEW_(pnt, item, defaultMemoryManager)
698 #define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor) \
699 SAFENEWWITHCONSTRUCTOR_(pnt, item, constructor, defaultMemoryManager)
701 #define SAFENEWARR(pnt, item, sz) \
702 SAFENEWARR_(pnt, item, sz, defaultMemoryManager)
704 #define SAFENEWARRNOFILL(pnt, item, sz) \
705 SAFENEWARRNOFILL_(pnt, item, sz, defaultMemoryManager)
707 #define SAFESTRDUP(pnt, src) \
708 SAFESTRDUP_(pnt, src, defaultMemoryManager)
710 #define SAFEDELETE(pnt) \
711 SAFEDELETE_(pnt, defaultMemoryManager)
713 #define SAFEDELETEARR(pnt) \
714 SAFEDELETEARR_(pnt, defaultMemoryManager)
716 #define SAFEDELETEANDFILLARR(pnt) \
717 SAFEDELETEANDFILLARR_(pnt, defaultMemoryManager)
#define MBDYN_EXCEPT_ARGS_PASSTHRU
#define MBDYN_EXCEPT_ARGS_DECL
std::ostream & operator<<(std::ostream &out, const FullMatrixHandler &m)
#define defaultMemoryManager