home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / dbgdel.cpp < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  57 lines

  1. /***
  2. *dbgnew.cpp - defines C++ delete() routines, debug version
  3. *
  4. *       Copyright (c) 1995-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Defines C++ delete() routines.
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _DEBUG
  12.  
  13. #include <cruntime.h>
  14. #include <malloc.h>
  15. #include <mtdll.h>
  16. #include <dbgint.h>
  17.  
  18. /***
  19. *void operator delete() - delete a block in the debug heap
  20. *
  21. *Purpose:
  22. *       Deletes any type of block.
  23. *
  24. *Entry:
  25. *       void *pUserData - pointer to a (user portion) of memory block in the
  26. *                         debug heap
  27. *
  28. *Return:
  29. *       <void>
  30. *
  31. *******************************************************************************/
  32. void operator delete(
  33.         void *pUserData
  34.         )
  35. {
  36.         _CrtMemBlockHeader * pHead;
  37.  
  38.         if (pUserData == NULL)
  39.             return;
  40.  
  41.         _mlock(_HEAP_LOCK);  /* block other threads */
  42.  
  43.         /* get a pointer to memory block header */
  44.         pHead = pHdr(pUserData);
  45.  
  46.          /* verify block type */
  47.         _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
  48.  
  49.         _free_dbg( pUserData, pHead->nBlockUse );
  50.  
  51.         _munlock(_HEAP_LOCK);  /* release other threads */
  52.  
  53.         return;
  54. }
  55.  
  56. #endif  /* _DEBUG */
  57.