home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_09 / single2 / mobject.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-07  |  2.3 KB  |  92 lines

  1. //  Listing 5
  2. //    mobject.h
  3. //
  4. //  Copyright Singleton Systems Ltd 1994
  5.  
  6. #if !defined (_MOBJECT_H_)
  7. #define _MOBJECT_H_
  8.  
  9. #if !defined (_FARHEAPB_H_)
  10. #include    "farheapb.h"
  11. #endif 
  12.  
  13. #define FP_MOBJECT MemoryObject FAR *
  14. #define VP_MOBJECT MemoryObject BASED_VOID *
  15. #define MO_BASED_VOID_FROM_LP(lp) \
  16.                 ((VP_MOBJECT) (OFFSETOF(lp)))
  17.  
  18. #if defined (_DEBUG)
  19. #define MO_DEBUG_NEW new(THIS_FILE, __LINE__)
  20. #else
  21. #define MO_DEBUG_NEW new
  22. #endif 
  23.  
  24. class FAR MemoryObject
  25. {
  26. friend FarHeapBlock::FarHeapBlock ();  
  27. private: 
  28. HGLOBAL    my_heap_block;
  29. MemoryObject BASED_VOID * prev_mo, 
  30.              BASED_VOID * next_mo; 
  31. unsigned int mo_block_size;
  32. enum flag_values {unallocated = 0, allocated = 1};
  33. #if defined (_DEBUG)
  34.     unsigned int flags;
  35.     char validity_tag [4];
  36.     static char validity_tag_value [4];
  37.     int Lno;                  
  38.     //  Line number of file which created object
  39.     char FAR * Fname;       
  40.     //  File name of file which created object
  41. #endif
  42.  
  43. //  Functions
  44. public:
  45. static void FAR * AllocateBlock (int required_size);
  46. static void ReturnBlock (void FAR * p_block);
  47.  
  48. void FAR * operator new (size_t size); 
  49. //  standard operator new, used for derived classes.
  50. private:
  51. void FAR * operator new (size_t, size_t size);
  52. //  Extended operator new, used by AllocateBlock 
  53. //  and standard operator new
  54.  
  55. public:
  56. #if defined (_DEBUG)
  57.     //  For file name and line number tracking
  58.     void FAR * operator new 
  59.             (size_t size, 
  60.              const char FAR * FileName, 
  61.              int Line);
  62.     
  63.     static void DumpAllObjects ();
  64. #endif
  65. void operator delete (void FAR * p_mo);
  66. MemoryObject ();
  67. ~MemoryObject ();
  68.  
  69. private:
  70. static FP_MOBJECT FindFreeSpace 
  71.             (size_t size, FP_FHB & block_allocated);
  72. void SetAllocationFlag (int flag_val);
  73. void SetFirstMemoryObject (HGLOBAL hglob, 
  74.                            unsigned size);
  75.  
  76. public:
  77. static void PrintHeapReport (ostream & os, 
  78.                              char * msg = NULL);
  79.  
  80. static BOOL MemoryHeapIsEmpty ();
  81. //  Returns TRUE if there are no MemoryObjects 
  82. //  currently allocated
  83.  
  84. static int MemoryHeapInUseCount ();
  85. //  Returns the number of objects currently allocated
  86.  
  87. static int HeapBlockInUseCount ();
  88. //  Returns the number of FarHeapBlocks currently 
  89. //  allocated
  90. };
  91. #endif
  92.