home *** CD-ROM | disk | FTP | other *** search
- #ifndef __HANDLEMANAGER__
- #define __HANDLEMANAGER__ 1
-
- #pragma once
-
- #ifndef __STDDEF__
- #include <stddef.h>
- #endif
-
- #ifndef __TYPES__
- #include <types.h>
- #endif
-
-
-
- /*
- ** HandleManager
- ** The Macintosh allows handles to be allocated from the application heap,
- ** the system heap and the MultiFinder heap. Frequently, a user of handles
- ** will want all handles to be allocated from a particular heap. However,
- ** the various flavors of heap have subtle differences which should be
- ** encapsulated within a class. Consequently, a HandleManager class is
- ** defined which encapsulates these differences
- */
-
-
- //µ enum HandleManagerHeap
- enum HandleManagerHeap {
- kAppHandleManager, // Allocate from application heap
- kSysHandleManager, // Allocate from the system heap
- kTempHandleManager // Allocate from the temporary (nee MultiFinder) heap
- };
-
-
-
-
- //
- //µ class HandleManager
- // This class exports routines for allocating, resizing and disposing of
- // handles. The base class provides support for the application heap; the
- // derived classes support the system heap and the temporary memory heaps.
- class HandleManager : public SingleObject {
- public:
- virtual void SetHandleSize(void **aHandle, size_t newSize, OSErr *anErr);
- virtual size_t GetHandleSize(void **aHandle, OSErr *anErr);
- // Set/get the size of the handle
-
- virtual void HLock(void **aHandle, OSErr *anErr);
- virtual void HUnlock(void **aHandle, OSErr *anErr);
- virtual void MoveHHi(void **aHandle, OSErr *anErr);
- // Handle munging operations
-
- virtual void **NewHandle(size_t aSize, OSErr *anErr);
- virtual void DisposHandle(void **aHandle, OSErr *anErr);
- // Allocate and dispose handles
-
- virtual void Duplicate(void **aSrcHandle, void ***aDstHandle, OSErr *anErr);
- // Make a copy of a handle. aDstHandle is a pointer to a handle. On
- // successful return, it will be a copy of the values in aSrcHandle.
-
- virtual size_t FreeMem();
- virtual size_t MaxMem(size_t *grow);
- // FreeMem returns the total free memory. MaxMem compacts the heap zone
- // and returns the size of the largest contiguous block available for
- // allocation. "grow" is set to the maximum number of bytes by which the
- // zone can grow. The value is 0 for all but the application heap.
-
-
- public:
- static HandleManager *GetManager(HandleManagerHeap whichHeap);
- // This static method returns a pointer to a HandleManager for the
- // requested heap.
-
-
- static void SetMaySpecifyTempMemory(Boolean yesToTempMemory);
- static HandleManager* GetLargestManager();
- // These two methods work with each other. "GetLargestManager"
- // returns that manager which has the largest amount of free space,
- // either the application heap or the temporary multifinder memory
- // heap. "SetMaySpecifyTempMemory" is passed true if GetLargestManager
- // is allowed to name multifinder memory, false if only the application
- // heap is allowed to satisfy requests. The default setting is false,
- // only the application heap is allowed.
-
-
- private:
- static Boolean fMaySpecifyTempMemory;
-
-
- protected:
- inline void *operator new(size_t);
- inline void operator delete(void *);
- // Make these private. Instances are not created or deleted.
- };
-
-
- //µ HandleManager::SetMaySpecifyTempMemory
- #pragma segment HandleManager
- inline void HandleManager::SetMaySpecifyTempMemory(Boolean yesToTempMemory)
- {
- fMaySpecifyTempMemory = yesToTempMemory;
- }
-
-
- //µ HandleManager::operator
- #pragma segment HandleManager
- inline void *HandleManager::operator new(size_t)
- {
- return (0);
- }
-
-
- //µ HandleManager::operator
- #pragma segment HandleManager
- inline void HandleManager::operator delete(void *)
- {
- }
-
-
- #endif
-
-
-