home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++Source Code Fmtr Folder / Src / HandleManager.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  3.5 KB  |  123 lines  |  [TEXT/MPS ]

  1. #ifndef __HANDLEMANAGER__
  2. #define __HANDLEMANAGER__    1
  3.  
  4. #pragma once
  5.  
  6. #ifndef __STDDEF__
  7. #include <stddef.h>
  8. #endif
  9.  
  10. #ifndef __TYPES__
  11. #include <types.h>
  12. #endif
  13.  
  14.  
  15.  
  16. /*
  17. ** HandleManager
  18. **    The Macintosh allows handles to be allocated from the application heap,
  19. ** the system heap and the MultiFinder heap.  Frequently, a user of handles
  20. ** will want all handles to be allocated from a particular heap.  However,
  21. ** the various flavors of heap have subtle differences which should be
  22. ** encapsulated within a class.  Consequently, a HandleManager class is
  23. ** defined which encapsulates these differences
  24. */
  25.  
  26.  
  27. //µ enum HandleManagerHeap
  28. enum HandleManagerHeap {
  29.     kAppHandleManager,                            // Allocate from application heap
  30.     kSysHandleManager,                            // Allocate from the system heap
  31.     kTempHandleManager                            // Allocate from the temporary (nee MultiFinder) heap
  32. };
  33.  
  34.  
  35.  
  36.  
  37. //
  38. //µ class HandleManager
  39. //    This class exports routines for allocating, resizing and disposing of
  40. // handles.  The base class provides support for the application heap; the
  41. // derived classes support the system heap and the temporary memory heaps.
  42. class HandleManager : public SingleObject {
  43. public:
  44.     virtual void SetHandleSize(void **aHandle, size_t newSize, OSErr *anErr);
  45.     virtual size_t GetHandleSize(void **aHandle, OSErr *anErr);
  46.     // Set/get the size of the handle
  47.  
  48.     virtual void HLock(void **aHandle, OSErr *anErr);
  49.     virtual void HUnlock(void **aHandle, OSErr *anErr);
  50.     virtual void MoveHHi(void **aHandle, OSErr *anErr);
  51.     // Handle munging operations
  52.  
  53.     virtual void **NewHandle(size_t aSize, OSErr *anErr);
  54.     virtual void DisposHandle(void **aHandle, OSErr *anErr);
  55.     // Allocate and dispose handles
  56.  
  57.     virtual void Duplicate(void **aSrcHandle, void ***aDstHandle, OSErr *anErr);
  58.     // Make a copy of a handle.  aDstHandle is a pointer to a handle.  On
  59.     // successful return, it will be a copy of the values in aSrcHandle.
  60.  
  61.     virtual size_t FreeMem();
  62.     virtual size_t MaxMem(size_t *grow);
  63.     // FreeMem returns the total free memory.  MaxMem compacts the heap zone
  64.     // and returns the size of the largest contiguous block available for
  65.     // allocation.  "grow" is set to the maximum number of bytes by which the
  66.     // zone can grow.  The value is 0 for all but the application heap.
  67.  
  68.  
  69. public:
  70.     static HandleManager *GetManager(HandleManagerHeap whichHeap);
  71.     // This static method returns a pointer to a HandleManager for the
  72.     // requested heap.
  73.  
  74.  
  75.     static void SetMaySpecifyTempMemory(Boolean yesToTempMemory);
  76.     static HandleManager* GetLargestManager();
  77.     // These two methods work with each other.  "GetLargestManager"
  78.     // returns that manager which has the largest amount of free space,
  79.     // either the application heap or the temporary multifinder memory
  80.     // heap.  "SetMaySpecifyTempMemory" is passed true if GetLargestManager
  81.     // is allowed to name multifinder memory, false if only the application
  82.     // heap is allowed to satisfy requests.  The default setting is false,
  83.     // only the application heap is allowed.
  84.  
  85.  
  86. private:
  87.     static Boolean fMaySpecifyTempMemory;
  88.  
  89.  
  90. protected:
  91.     inline void *operator new(size_t);
  92.     inline void operator delete(void *);
  93.     // Make these private.  Instances are not created or deleted.
  94. };
  95.  
  96.  
  97. //µ   HandleManager::SetMaySpecifyTempMemory
  98. #pragma segment HandleManager
  99. inline void HandleManager::SetMaySpecifyTempMemory(Boolean yesToTempMemory)
  100. {
  101.     fMaySpecifyTempMemory = yesToTempMemory;
  102. }
  103.  
  104.  
  105. //µ HandleManager::operator
  106. #pragma segment HandleManager
  107. inline void *HandleManager::operator new(size_t)
  108. {
  109.     return (0);
  110. }
  111.  
  112.  
  113. //µ HandleManager::operator
  114. #pragma segment HandleManager
  115. inline void HandleManager::operator delete(void *)
  116. {
  117. }
  118.  
  119.  
  120. #endif
  121.  
  122.  
  123.