home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ODMemory.h
-
- Contains: Memory calls (wrappers around MemMgr.h) that throw exceptions.
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
-
- In Progress:
-
- */
-
- #ifndef _ODMEMORY_
- #define _ODMEMORY_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
-
- #ifdef _OD_IMPL_SHARE_UTILS_
- #pragma import on
- #endif
-
- #ifdef __cplusplus
- #define DEFAULT(V) =(V)
- extern "C" {
- #else
- #define DEFAULT(V) /**/
- #endif
-
- //========================================================================================
- // Type definitions
- //========================================================================================
-
- typedef struct MemHeap MemHeap;
- typedef MemHeap* ODMemoryHeapID; // An anonymous pointer type
-
- typedef ODULong ODBlockSize;
-
- //========================================================================================
- // Constant definitions
- //========================================================================================
-
- #define kDefaultHeapID ((ODMemoryHeapID) 0L)
-
-
- //========================================================================================
- // Initialization (MUST call this before using ODNewPtr[Clear] or ODGetDefaultHeap)
- //========================================================================================
-
- OSErr InitODMemory( );
-
- //========================================================================================
- // Operations on heaps
- //========================================================================================
-
- ODMemoryHeapID ODGetDefaultHeap();
- //ODMemoryHeapID ODGetSystemHeap();
-
- ODMemoryHeapID ODCreateHeap(ODULong initialSize, ODULong growBy, Boolean fromSysMemory,
- const char *name);
- void ODDestroyHeap(ODMemoryHeapID heapID);
-
- //========================================================================================
- // Operations on pointer based blocks
- //========================================================================================
-
- // ----- Allocation and freeing
-
- void* ODNewPtr(ODBlockSize size, ODMemoryHeapID heapID DEFAULT(kDefaultHeapID) );
- void* ODNewPtrClear(ODBlockSize size, ODMemoryHeapID heapID DEFAULT(kDefaultHeapID) );
- void* ODReallocate(void *block, ODBlockSize newSize);
- void ODDisposePtr(void *block);
-
- // ----- Utilities
-
- ODMemoryHeapID ODRecoverHeapID(const void *block);
-
- //========================================================================================
- // Operations on handle based blocks
- //========================================================================================
-
- // ----- Allocation and freeing
-
- ODHandle ODNewHandle(ODBlockSize howBig);
- void ODDisposeHandle(ODHandle handle);
- ODHandle ODCopyHandle(ODHandle handle);
-
- // ----- Block size accessors
-
- ODULong ODGetHandleSize(ODHandle handle);
- void ODSetHandleSize(ODHandle handle, ODBlockSize size);
-
- // ----- Locking and unlocking
-
- void* ODLockHandle(ODHandle handle);
- void ODUnlockPtr(void* ptr);
- void ODUnlockHandle(ODHandle handle);
-
- //========================================================================================
- // Utility functions
- //========================================================================================
-
- ODBoolean ODHaveFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
- ODBoolean appHeap DEFAULT(kODFalse) );
- void ODRequireFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
- ODBoolean appHeap DEFAULT(kODFalse) );
- void ODCheckAppHeapSpace();
-
-
- void ODBlockMove(const void *from, void *to, ODBlockSize size);
-
- void ODBlockIsObject( void *block, ODBoolean isObject ); // Called by ODObject::somInit
- ODBoolean ODIsBlockAnObject( const void *block );
-
- #ifdef _PLATFORM_MACINTOSH_
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- RgnHandle ODNewRgn( ); // Allocates rgn in temp-mem.
-
- #ifdef __cplusplus
- inline RgnHandle ODCopyRgn( RgnHandle r )
- {return (RgnHandle)ODCopyHandle((ODHandle)r);}
- #else
- #define ODCopyRgn(R) ((RgnHandle)ODCopyHandle((ODHandle)(R)))
- #endif
-
- #endif /*_PLATFORM_MACINTOSH_*/
-
-
- #ifdef __cplusplus
- }
- #endif
-
- #ifdef _OD_IMPL_SHARE_UTILS_
- #pragma import off
- #endif
-
- #endif /*_ODMEMORY_*/
-