home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / ODUtils / ODMemory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  5.1 KB  |  183 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ODMemory.h
  3.  
  4.     Contains:    Memory calls (wrappers around MemMgr.h) that throw exceptions.
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     7/14/96    TJ        Fixed priveledges on
  13.                                     COverridingMacOSMemory.
  14.          <3>     6/19/96    jpa        1357406: Added COverridingMacOSMemory.
  15.          <2>     5/24/96    jpa        1.1MRD: pragma internal eliminates NOPs.
  16.     
  17.     In Progress:
  18.         
  19. */
  20.  
  21. #ifndef _ODMEMORY_
  22. #define _ODMEMORY_
  23.  
  24. #ifndef _ODTYPES_
  25. #include "ODTypes.h"
  26. #endif
  27.  
  28. #ifndef _EXCEPT_
  29. #include "Except.h"
  30. #endif
  31.  
  32. #ifndef __CODEFRAGMENTS__
  33. #include <CodeFragments.h>
  34. #endif
  35.  
  36.  
  37. #ifdef _OD_IMPL_SHARE_UTILS_
  38. #pragma import on
  39. #elif defined(PRAGMA_INTERNAL_SUPPORTED)
  40. #pragma internal on
  41. #endif
  42.  
  43. #ifdef __cplusplus
  44. #define DEFAULT(V)    =(V)
  45. extern "C" {
  46. #else
  47. #define DEFAULT(V)    /**/
  48. #endif
  49.  
  50. //========================================================================================
  51. // Type definitions
  52. //========================================================================================
  53.  
  54. typedef struct MemHeap MemHeap;
  55. typedef MemHeap* ODMemoryHeapID;        // An anonymous pointer type
  56.  
  57. typedef ODULong ODBlockSize;
  58.  
  59. //========================================================================================
  60. // Constant definitions
  61. //========================================================================================
  62.  
  63. #define kDefaultHeapID ((ODMemoryHeapID) 0L)
  64.  
  65.  
  66. //========================================================================================
  67. // Initialization        (MUST call this before using ODNewPtr[Clear] or ODGetDefaultHeap)
  68. //========================================================================================
  69.  
  70. OSErr InitODMemory( );
  71.  
  72. //========================================================================================
  73. // Operations on heaps
  74. //========================================================================================
  75.  
  76. ODMemoryHeapID    ODGetDefaultHeap();
  77. //ODMemoryHeapID    ODGetSystemHeap();
  78.  
  79. ODMemoryHeapID    ODCreateHeap(ODULong initialSize, ODULong growBy, Boolean fromSysMemory,
  80.                             const char *name);
  81. void            ODDestroyHeap(ODMemoryHeapID heapID);
  82.  
  83. //========================================================================================
  84. // Operations on pointer based blocks
  85. //========================================================================================
  86.  
  87. // ----- Allocation and freeing
  88.  
  89. void*        ODNewPtr(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  90. void*        ODNewPtrClear(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  91. void*        ODReallocate(void *block, ODBlockSize newSize);
  92. void         ODDisposePtr(void *block);
  93.  
  94. // ----- Utilities
  95.  
  96. ODMemoryHeapID ODRecoverHeapID(const void *block);
  97.  
  98. //========================================================================================
  99. // Operations on handle based blocks
  100. //========================================================================================
  101.  
  102. // ----- Allocation and freeing
  103.  
  104. ODHandle    ODNewHandle(ODBlockSize howBig);
  105. void        ODDisposeHandle(ODHandle handle);
  106. ODHandle    ODCopyHandle(ODHandle handle);
  107.  
  108. // ----- Block size accessors
  109.  
  110. ODULong        ODGetHandleSize(ODHandle handle);
  111. void        ODSetHandleSize(ODHandle handle, ODBlockSize size);
  112.  
  113. // ----- Locking and unlocking
  114.  
  115. void*        ODLockHandle(ODHandle handle);
  116. void        ODUnlockPtr(void* ptr);
  117. void        ODUnlockHandle(ODHandle handle);
  118.  
  119. //========================================================================================
  120. // Utility functions
  121. //========================================================================================
  122.  
  123. ODBoolean    ODHaveFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  124.                              ODBoolean appHeap DEFAULT(kODFalse) );
  125. void        ODRequireFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  126.                                 ODBoolean appHeap DEFAULT(kODFalse) );
  127. void        ODCheckAppHeapSpace();
  128.  
  129.  
  130. void        ODBlockMove(const void *from, void *to, ODBlockSize size);
  131.  
  132. void        ODBlockIsObject( void *block, ODBoolean isObject );    // Called by ODObject::somInit
  133. ODBoolean    ODIsBlockAnObject( const void *block );
  134.  
  135. //========================================================================================
  136. // MacOS NewPtr/NewHandle override
  137. //========================================================================================
  138.  
  139. #ifdef _PLATFORM_MACINTOSH_
  140.  
  141. class COverridingMacOSMemory : Destructo {
  142.     public:
  143.      COverridingMacOSMemory( );
  144.     ~COverridingMacOSMemory( );
  145. };
  146.  
  147. #endif /*_PLATFORM_MACINTOSH_*/
  148.  
  149.  
  150. //========================================================================================
  151. // MacOS Region operations
  152. //========================================================================================
  153.  
  154. #ifdef _PLATFORM_MACINTOSH_
  155.  
  156. #ifndef __QUICKDRAW__
  157. #include <QuickDraw.h>
  158. #endif
  159.  
  160. RgnHandle    ODNewRgn( );                                    // Allocates rgn in temp-mem.
  161.  
  162. #ifdef __cplusplus
  163.     inline RgnHandle ODCopyRgn( RgnHandle r )
  164.             {return (RgnHandle)ODCopyHandle((ODHandle)r);}
  165. #else
  166.     #define ODCopyRgn(R)    ((RgnHandle)ODCopyHandle((ODHandle)(R)))
  167. #endif
  168.  
  169. #endif /*_PLATFORM_MACINTOSH_*/
  170.  
  171.  
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175.  
  176. #ifdef _OD_IMPL_SHARE_UTILS_
  177. #pragma import off
  178. #elif defined(PRAGMA_INTERNAL_SUPPORTED)
  179. #pragma internal reset
  180. #endif
  181.  
  182. #endif /*_ODMEMORY_*/
  183.