home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / ODMEMORY.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  8KB  |  212 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odutils
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //       
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.13 com/src/utils/include/ODMemory.h, odutils, od96os2, odos29646d 7/15/96 18:01:00 [ 11/15/96 15:29:00 ]
  28. /*
  29.     File:        ODMemory.h
  30.  
  31.     Contains:    Memory calls (wrappers around MemMgr.h) that throw exceptions.
  32.  
  33.     Owned by:    Jens Alfke
  34.  
  35.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37.     
  38.     In Progress:
  39.         
  40. */
  41.  
  42. #ifndef _ODMEMORY_
  43. #define _ODMEMORY_
  44.  
  45. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  46. // ***********************
  47. // See notes in ODMemory.cpp that explain ODMemory porting rationale (e.g., why
  48. // certain functions are #ifdef'ed out or stubbed out, etc.).
  49. // ***********************
  50. #endif // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  51.  
  52. #ifndef _ODTYPES_
  53. #include "ODTypes.h"
  54. #endif
  55.  
  56. #ifdef _PLATFORM_MACINTOSH_
  57. #ifndef __CODEFRAGMENTS__
  58. #include <CodeFragments.h>
  59. #endif
  60. #endif // _PLATFORM_MACINTOSH_
  61.  
  62. #if defined(_PLATFORM_WIN32_)
  63. #include <wtypes.h>
  64. #include <winbase.h>
  65. #endif // defined(_PLATFORM_WIN32_)
  66.  
  67.  
  68. #ifdef _OD_IMPL_SHARE_UTILS_
  69. #pragma import on
  70. #endif
  71.  
  72. #ifdef __cplusplus
  73. #define DEFAULT(V)    =(V)
  74. extern "C" {
  75. #else
  76. #define DEFAULT(V)    /**/
  77. #endif
  78.  
  79. //========================================================================================
  80. // Type definitions
  81. //========================================================================================
  82.  
  83. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  84. typedef struct MemHeap MemHeap;
  85. typedef MemHeap* ODMemoryHeapID;        // An anonymous pointer type
  86. #else // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  87.  
  88. #if defined(_PLATFORM_WIN32_)
  89. typedef HANDLE ODMemoryHeapID;
  90. #endif // defined(_PLATFORM_WIN32_)
  91.  
  92. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  93. typedef void  *ODMemoryHeapID;
  94. #endif // defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  95.  
  96. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  97.  
  98. typedef ODULong ODBlockSize;
  99.  
  100. //========================================================================================
  101. // Constant definitions
  102. //========================================================================================
  103.  
  104. #define kDefaultHeapID ((ODMemoryHeapID) 0L)
  105.  
  106.  
  107. //========================================================================================
  108. // Initialization        (MUST call this before using ODNewPtr[Clear] or ODGetDefaultHeap)
  109. //========================================================================================
  110.  
  111. OSErr InitODMemory( );
  112.  
  113. //========================================================================================
  114. // Operations on heaps
  115. //========================================================================================
  116.  
  117. ODMemoryHeapID    ODGetDefaultHeap();
  118. //ODMemoryHeapID    ODGetSystemHeap();
  119.  
  120. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  121. ODMemoryHeapID    ODCreateHeap(ODULong initialSize, ODULong growBy, Boolean fromSysMemory,
  122.                             const char *name);
  123. void            ODDestroyHeap(ODMemoryHeapID heapID);
  124. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  125.  
  126. //========================================================================================
  127. // Operations on pointer based blocks
  128. //========================================================================================
  129.  
  130. // ----- Allocation and freeing
  131.  
  132. void*        ODNewPtr(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  133. void*        ODNewPtrClear(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  134. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  135. void*        ODReallocate(void *block, ODBlockSize newSize);
  136. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  137. void         ODDisposePtr(void *block);
  138.  
  139. // ----- Utilities
  140.  
  141. ODMemoryHeapID ODRecoverHeapID(const void *block);
  142.  
  143. //========================================================================================
  144. // Operations on handle based blocks
  145. //========================================================================================
  146.  
  147. // ----- Allocation and freeing
  148.  
  149. ODHandle    ODNewHandle(ODBlockSize howBig);
  150. void        ODDisposeHandle(ODHandle handle);
  151. ODHandle    ODCopyHandle(ODHandle handle);
  152.  
  153. // ----- Block size accessors
  154.  
  155. ODULong        ODGetHandleSize(ODHandle handle);
  156. void        ODSetHandleSize(ODHandle handle, ODBlockSize size);
  157.  
  158. // ----- Locking and unlocking
  159.  
  160. void*        ODLockHandle(ODHandle handle);
  161. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  162. void        ODUnlockPtr(void* ptr);
  163. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  164. void        ODUnlockHandle(ODHandle handle);
  165.  
  166. //========================================================================================
  167. // Utility functions
  168. //========================================================================================
  169.  
  170. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  171. ODBoolean    ODHaveFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  172.                              ODBoolean appHeap DEFAULT(kODFalse) );
  173. void        ODRequireFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  174.                                 ODBoolean appHeap DEFAULT(kODFalse) );
  175. void        ODCheckAppHeapSpace();
  176. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  177.  
  178.  
  179. void        ODBlockMove(const void *from, void *to, ODBlockSize size);
  180.  
  181. #if !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  182. void        ODBlockIsObject( void *block, ODBoolean isObject );    // Called by ODObject::somInit
  183. ODBoolean    ODIsBlockAnObject( const void *block );
  184. #endif // !defined(_PLATFORM_WIN32_) && !defined(_PLATFORM_OS2_) && !defined(_PLATFORM_UNIX_)
  185.  
  186. #ifdef _PLATFORM_MACINTOSH_
  187. #ifndef __QUICKDRAW__
  188. #include <QuickDraw.h>
  189. #endif
  190.  
  191. RgnHandle    ODNewRgn( );                                    // Allocates rgn in temp-mem.
  192.  
  193. #ifdef __cplusplus
  194.     inline RgnHandle ODCopyRgn( RgnHandle r )
  195.             {return (RgnHandle)ODCopyHandle((ODHandle)r);}
  196. #else
  197.     #define ODCopyRgn(R)    ((RgnHandle)ODCopyHandle((ODHandle)(R)))
  198. #endif
  199.  
  200. #endif /*_PLATFORM_MACINTOSH_*/
  201.  
  202.  
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206.  
  207. #ifdef _OD_IMPL_SHARE_UTILS_
  208. #pragma import off
  209. #endif
  210.  
  211. #endif /*_ODMEMORY_*/
  212.