home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / OpenDoc / OpenDoc Utilities / Interfaces / ODMemory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  5.3 KB  |  185 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.          <5>     9/17/96    RA        1376573: ODMemory.h does not compile under
  13.                                     C compilers or MrCpp compiler
  14.          <4>     7/14/96    TJ        Fixed priveledges on
  15.                                     COverridingMacOSMemory.
  16.          <3>     6/19/96    jpa        1357406: Added COverridingMacOSMemory.
  17.          <2>     5/24/96    jpa        1.1MRD: pragma internal eliminates NOPs.
  18.     
  19.     In Progress:
  20.         
  21. */
  22.  
  23. #ifndef _ODMEMORY_
  24. #define _ODMEMORY_
  25.  
  26. #ifndef _ODTYPES_
  27. #include "ODTypes.h"
  28. #endif
  29.  
  30. #ifndef _EXCEPT_
  31. #include "Except.h"
  32. #endif
  33.  
  34. #ifndef __CODEFRAGMENTS__
  35. #include <CodeFragments.h>
  36. #endif
  37.  
  38.  
  39. #ifdef _OD_IMPL_SHARE_UTILS_
  40. #pragma import on
  41. #elif defined(PRAGMA_INTERNAL_SUPPORTED)
  42. #pragma internal on
  43. #endif
  44.  
  45. #ifdef __cplusplus
  46. #define DEFAULT(V)    =(V)
  47. extern "C" {
  48. #else
  49. #define DEFAULT(V)    /**/
  50. #endif
  51.  
  52. //========================================================================================
  53. // Type definitions
  54. //========================================================================================
  55.  
  56. typedef struct MemHeap MemHeap;
  57. typedef MemHeap* ODMemoryHeapID;        // An anonymous pointer type
  58.  
  59. typedef ODULong ODBlockSize;
  60.  
  61. //========================================================================================
  62. // Constant definitions
  63. //========================================================================================
  64.  
  65. #define kDefaultHeapID ((ODMemoryHeapID) 0L)
  66.  
  67.  
  68. //========================================================================================
  69. // Initialization        (MUST call this before using ODNewPtr[Clear] or ODGetDefaultHeap)
  70. //========================================================================================
  71.  
  72. OSErr InitODMemory( );
  73.  
  74. //========================================================================================
  75. // Operations on heaps
  76. //========================================================================================
  77.  
  78. ODMemoryHeapID    ODGetDefaultHeap();
  79. //ODMemoryHeapID    ODGetSystemHeap();
  80.  
  81. ODMemoryHeapID    ODCreateHeap(ODULong initialSize, ODULong growBy, Boolean fromSysMemory,
  82.                             const char *name);
  83. void            ODDestroyHeap(ODMemoryHeapID heapID);
  84.  
  85. //========================================================================================
  86. // Operations on pointer based blocks
  87. //========================================================================================
  88.  
  89. // ----- Allocation and freeing
  90.  
  91. void*        ODNewPtr(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  92. void*        ODNewPtrClear(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  93. void*        ODReallocate(void *block, ODBlockSize newSize);
  94. void         ODDisposePtr(void *block);
  95.  
  96. // ----- Utilities
  97.  
  98. ODMemoryHeapID ODRecoverHeapID(const void *block);
  99.  
  100. //========================================================================================
  101. // Operations on handle based blocks
  102. //========================================================================================
  103.  
  104. // ----- Allocation and freeing
  105.  
  106. ODHandle    ODNewHandle(ODBlockSize howBig);
  107. void        ODDisposeHandle(ODHandle handle);
  108. ODHandle    ODCopyHandle(ODHandle handle);
  109.  
  110. // ----- Block size accessors
  111.  
  112. ODULong        ODGetHandleSize(ODHandle handle);
  113. void        ODSetHandleSize(ODHandle handle, ODBlockSize size);
  114.  
  115. // ----- Locking and unlocking
  116.  
  117. void*        ODLockHandle(ODHandle handle);
  118. void        ODUnlockPtr(void* ptr);
  119. void        ODUnlockHandle(ODHandle handle);
  120.  
  121. //========================================================================================
  122. // Utility functions
  123. //========================================================================================
  124.  
  125. ODBoolean    ODHaveFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  126.                              ODBoolean appHeap DEFAULT(kODFalse) );
  127. void        ODRequireFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  128.                                 ODBoolean appHeap DEFAULT(kODFalse) );
  129. void        ODCheckAppHeapSpace();
  130.  
  131.  
  132. void        ODBlockMove(const void *from, void *to, ODBlockSize size);
  133.  
  134. void        ODBlockIsObject( void *block, ODBoolean isObject );    // Called by ODObject::somInit
  135. ODBoolean    ODIsBlockAnObject( const void *block );
  136.  
  137. //========================================================================================
  138. // MacOS Region operations
  139. //========================================================================================
  140.  
  141. #ifdef _PLATFORM_MACINTOSH_
  142.  
  143. #ifndef __QUICKDRAW__
  144. #include <QuickDraw.h>
  145. #endif
  146.  
  147. RgnHandle    ODNewRgn( );                                    // Allocates rgn in temp-mem.
  148.  
  149. #ifdef __cplusplus
  150.     inline RgnHandle ODCopyRgn( RgnHandle r )
  151.             {return (RgnHandle)ODCopyHandle((ODHandle)r);}
  152. #else
  153.     #define ODCopyRgn(R)    ((RgnHandle)ODCopyHandle((ODHandle)(R)))
  154. #endif
  155.  
  156. #endif /*_PLATFORM_MACINTOSH_*/
  157.  
  158. //========================================================================================
  159. // MacOS NewPtr/NewHandle override
  160. //========================================================================================
  161.  
  162. #ifdef __cplusplus               // CHANGE BY SAMPLE CODE TEAM TO ALLOW USE W/ C and MrCpp compilers
  163.     } // ends extern "C"
  164.  
  165. #ifdef _PLATFORM_MACINTOSH_
  166.  
  167. class COverridingMacOSMemory : private Destructo {
  168.     public:
  169.      COverridingMacOSMemory( );
  170.     ~COverridingMacOSMemory( );
  171. };
  172.  
  173. #endif /*_PLATFORM_MACINTOSH_*/
  174.  
  175. #endif /*__cplusplus*/
  176.  
  177.  
  178. #ifdef _OD_IMPL_SHARE_UTILS_
  179. #pragma import off
  180. #elif defined(PRAGMA_INTERNAL_SUPPORTED)
  181. #pragma internal reset
  182. #endif
  183.  
  184. #endif /*_ODMEMORY_*/
  185.