#include <ccobject.h>
Inheritance diagram for SimpleCCObject:
Public Member Functions | |
void * | operator new (size_t, void *p) |
void * | operator new (size_t nSize) |
This function allocates a block of memory to create a new SimpleCCObject derived thingy. This does not throw an exception, but returns NULL in the event of a failure. In debug builds it also keeps track of all allocations and will give a dump of all reamining blobs of memory when camelot exits. | |
void | operator delete (void *p) |
I think you can work this one out! In debug builds this will also remove items from the memory tracking list. | |
void * | operator new (size_t nSize, LPCSTR lpszFileName, INT32 nLine) |
This functions adds an item into the memory tracking list and stores the filename and line number if it is passed in. Both versions of new call this function to handle all there DEBUG stuff.A version of the new operator that stores the filename etc into the memory tracking structure to help in debugging. This can be activated by including the following line :- MonoOn define new CAM_DEBUG_NEW MonoOff after all the IMPLEMENT_DYNAMIC() etc macros. | |
Static Public Member Functions | |
static void | MemoryTrackAdd (void *p, LPCSTR Filename, INT32 Line) |
static void | MemoryDump () |
Dumps the details of all objects allocated at the time of the call to the Debug window. | |
static BOOL | Init () |
Declares a preference that allows you to clear memory in delete(). |
Definition at line 180 of file ccobject.h.
|
|
Dumps the details of all objects allocated at the time of the call to the Debug window.
Definition at line 660 of file ccobject.cpp. 00661 { 00662 #ifdef _DEBUG 00663 // somewhere to hold the output string 00664 TCHAR OutputMsg[256]; 00665 00666 // Get a pointer to the head of the list of memory items 00667 MemTrackExtra *pItem = pHead; 00668 if( pItem != NULL ) 00669 TRACE( _T("......Memory Leaks Detected......\n")); 00670 00671 // loop through it 00672 while( pItem != NULL ) 00673 { 00674 PORTNOTE("other","Removed MFC CDumpContext") 00675 #ifndef EXCLUDE_FROM_XARALX 00676 ((CCObject*)(pItem->Start))->Dump(afxDump); 00677 #endif 00678 #if 0 != wxUSE_UNICODE 00679 TCHAR pFilename[22]; 00680 camMbstowcs(pFilename, pItem->Filename, 22); 00681 #else 00682 TCHAR* pFilename = pItem->Filename; 00683 #endif 00684 camSnprintf( OutputMsg, 256, _T("allocated in %s at line %d.\n"), pFilename, pItem->LineNum ); 00685 TRACE(OutputMsg); 00686 00687 // Get the next one along 00688 pItem = pItem->pNext; 00689 if (pItem==NULL) 00690 TRACE( _T("\n......End Of Memory Dump......\n")); 00691 } 00692 #endif 00693 }
|
|
|
|
I think you can work this one out! In debug builds this will also remove items from the memory tracking list.
Definition at line 575 of file ccobject.cpp. 00576 { 00577 // behave like normal delete 00578 if (p==NULL) 00579 return; 00580 00581 #ifdef _DEBUG 00582 // TRACE( _T("SimpleCCObject::delete at 0x%08x (0x%08x)\n"),p, ((char*)p) - sizeof(MemTrackExtra)); 00583 00584 // Get the real start of the block 00585 p = ((char*)p) - sizeof(MemTrackExtra); 00586 00587 // find out how big the block is 00588 #if !defined(__WXMAC__) 00589 size_t BlockLen = _msize(p); 00590 #else 00591 size_t BlockLen = malloc_size(p); 00592 #endif 00593 00594 #ifdef _OUTPUT_DEBUG 00595 TotalMemAllocated -= BlockLen; 00596 TRACE( _T("DeAllocated %ld\n"),TotalMemAllocated); 00597 #endif 00598 00599 // Find the start of my strange structure 00600 MemTrackExtra* pExtraInfo = (MemTrackExtra*)p; 00601 00602 // make sure that the guard word is still there 00603 if (pExtraInfo->GuardWord == GUARDWORD) 00604 { 00605 // yep, all seems well, so remove this item from the list 00606 // Update the head of the list if needed 00607 if (pExtraInfo == pHead) 00608 pHead = pExtraInfo->pNext; 00609 00610 // Update the next item in the list 00611 if (pExtraInfo->pNext!=NULL) 00612 pExtraInfo->pNext->pPrev = pExtraInfo->pPrev; 00613 00614 // update the previous item in the list 00615 if (pExtraInfo->pPrev!=NULL) 00616 pExtraInfo->pPrev->pNext = pExtraInfo->pNext; 00617 00618 // Write over the block with the dead memory land fill value 00619 memset(p, OLDLANDFILL, BlockLen); 00620 00621 // Destroy the guard word 00622 pExtraInfo->GuardWord = DEADGUARD; 00623 } 00624 else 00625 { 00626 if (pExtraInfo->GuardWord == DEADGUARD) 00627 ENSURE(FALSE, "Memory was de-alloced more than once...\n"); // Debug 00628 else 00629 ENSURE(FALSE, "ALERT!!!! Memory Tracker thinks that memory is toast...\n"); // Debug 00630 00631 // either way, the memory is not there to be freed 00632 return; 00633 } 00634 #endif 00635 00636 // free up the allocation 00637 free(p); 00638 00639 #ifdef _DEBUG 00640 // and check everything is OK 00641 if (CHECK_MEMORY) 00642 CheckMemory( TRUE ); 00643 #endif 00644 }
|
|
This functions adds an item into the memory tracking list and stores the filename and line number if it is passed in. Both versions of new call this function to handle all there DEBUG stuff.A version of the new operator that stores the filename etc into the memory tracking structure to help in debugging. This can be activated by including the following line :- MonoOn define new CAM_DEBUG_NEW MonoOff after all the IMPLEMENT_DYNAMIC() etc macros.
Reimplemented in DownloadOpParam. Definition at line 408 of file ccobject.cpp. 00409 { 00410 // First we have to make a note of the function pointer maintained by VC++ thats 00411 // called by malloc if it fails (as it currently throws an exception) 00412 // We have to set it to NULL to stop malloc doing anything when mem runs out 00413 #if !defined(__WXMAC__) 00414 _PNH old_handler = _set_new_handler( NULL ); 00415 #else 00416 new_handler pnh = set_new_handler(NULL); 00417 #endif 00418 00419 #ifdef _OUTPUT_DEBUG 00420 TotalMemAllocated += Size; 00421 TRACE( _T("Allocated %ld\n"),TotalMemAllocated); 00422 #endif 00423 00424 #ifdef _DEBUG 00425 // We actually want more memory to build our list out of 00426 Size += sizeof(MemTrackExtra); 00427 #endif 00428 00429 void* pStart = NULL; 00430 00431 // See if we are supposed to fail this memory claim for low memory simulation 00432 #ifdef _DEBUG 00433 if (FailingMemory) 00434 { 00435 if (Size < BytesBeforeFail) 00436 BytesBeforeFail -= Size; 00437 else 00438 goto Allocated; 00439 } 00440 #endif 00441 00442 // ask for the actual memory 00443 pStart = malloc(Size); 00444 00445 // finally repair the function pointer to its old value and return our pointer 00446 #if !defined(__WXMAC__) 00447 _set_new_handler( old_handler ); 00448 #else 00449 set_new_handler(pnh); 00450 #endif 00451 00452 // Do lots of tracking if in Debug mode 00453 #ifdef _DEBUG 00454 if (pStart!=NULL) 00455 { 00456 // Build in all the extra memory tracking info that we like to have 00457 MemoryTrackAdd(pStart, FileName, Line); 00458 } 00459 00460 Allocated: 00461 // We'll remove the label as well (to get rid of the warning) 00462 #endif 00463 // if the pointer is NULL then we should set the error handler 00464 if (pStart==NULL) 00465 { 00466 TRACE( wxT("ALERT! ALERT! new is about to return NULL, Watch out for unhandled errors\n") ); 00467 Error::SetError(_R(IDS_OUT_OF_MEMORY)); 00468 } 00469 00470 // TRACE( _T("SimpleCCObject::new at 0x%08x (0x%08x)\n"),((char*)pStart) + sizeof(MemTrackExtra), pStart); 00471 00472 #ifdef _DEBUG 00473 // return the pointer to the space after our tracking info 00474 return (((char*)pStart) + sizeof(MemTrackExtra)); 00475 #else 00476 // return the real start of the block 00477 return (pStart); 00478 #endif 00479 }
|
|
This function allocates a block of memory to create a new SimpleCCObject derived thingy. This does not throw an exception, but returns NULL in the event of a failure. In debug builds it also keeps track of all allocations and will give a dump of all reamining blobs of memory when camelot exits.
Reimplemented in DownloadOpParam. Definition at line 499 of file ccobject.cpp. 00500 { 00501 // First we have to make a note of the function pointer maintained by VC++ thats 00502 // called by malloc if it fails (as it currently throws an exception) 00503 // We have to set it to NULL to stop malloc doing anything when mem runs out 00504 #if !defined(__WXMAC__) 00505 _PNH old_handler = _set_new_handler( NULL ); 00506 #else 00507 new_handler pnh = set_new_handler(NULL); 00508 #endif 00509 00510 #ifdef _DEBUG 00511 // We actually want more memory to build our list out of 00512 Size += sizeof(MemTrackExtra); 00513 #endif 00514 00515 #ifdef _OUTPUT_DEBUG 00516 TotalMemAllocated += Size; 00517 TRACE( _T("Allocated %ld\n"),TotalMemAllocated); 00518 #endif 00519 00520 // ask for the actual memory 00521 void* pStart = malloc(Size); 00522 00523 // finally repair the function pointer to its old value and return our pointer 00524 #if !defined(__WXMAC__) 00525 _set_new_handler( old_handler ); 00526 #else 00527 set_new_handler(pnh); 00528 #endif 00529 00530 // Do lots of tracking if in Debug mode 00531 #ifdef _DEBUG 00532 // see if we have a NULL value returned from new 00533 if (pStart!=NULL) 00534 { 00535 // Build in all the extra memory tracking info that we like to have 00536 MemoryTrackAdd(pStart, NULL, 0); 00537 } 00538 #endif 00539 00540 // if the pointer is NULL then we should set the error handler 00541 if (pStart==NULL) 00542 { 00543 TRACE( wxT("ALERT! ALERT! new is about to return NULL, Watch out for unhandled errors\n") ); 00544 Error::SetError(_R(IDS_OUT_OF_MEMORY)); 00545 } 00546 00547 // TRACE( _T("SimpleCCObject::new at 0x%08x (0x%08x)\n"),((char*)pStart) + sizeof(MemTrackExtra), pStart); 00548 00549 #ifdef _DEBUG 00550 // return the pointer to the space after our tracking info 00551 return (((char*)pStart) + sizeof(MemTrackExtra)); 00552 #else 00553 // return the real start of the block 00554 return (pStart); 00555 #endif 00556 }
|
|
Definition at line 188 of file ccobject.h. 00188 { return p; }
|