home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWMemory / Sources / FWMemHlp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.0 KB  |  162 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMemHlp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef   FWMEMHLP_H
  13. #include "FWMemHlp.h"
  14. #endif
  15.  
  16. #ifndef   FWMEMMGR_H
  17. #include "FWMemMgr.h"
  18. #endif
  19.  
  20. #if FW_LIB_EXPORT_PRAGMAS
  21. #pragma lib_export on
  22. #endif
  23.  
  24. #ifdef FW_BUILD_MAC
  25. #pragma segment FWMemory
  26. #endif
  27.  
  28. //========================================================================================
  29. //    class FW_CAcquireLockedSystemHandle
  30. //========================================================================================
  31.  
  32. //----------------------------------------------------------------------------------------
  33. // FW_CAcquireLockedSystemHandle::FW_CAcquireLockedSystemHandle
  34. //----------------------------------------------------------------------------------------
  35.  
  36. FW_CAcquireLockedSystemHandle::FW_CAcquireLockedSystemHandle(FW_PlatformHandle aSystemHandle)
  37.                      : fLockedSystemHandle(aSystemHandle), 
  38.                        fLockedPointer(FW_CMemoryManager::LockSystemHandle(aSystemHandle))
  39. {
  40.     FW_END_CONSTRUCTOR
  41. }
  42.  
  43. //----------------------------------------------------------------------------------------
  44. // FW_CAcquireLockedSystemHandle::~FW_CAcquireLockedSystemHandle
  45. //----------------------------------------------------------------------------------------
  46.  
  47. FW_CAcquireLockedSystemHandle::~FW_CAcquireLockedSystemHandle()
  48. {
  49.     FW_START_DESTRUCTOR
  50.     FW_CMemoryManager::UnlockSystemHandle(fLockedSystemHandle);
  51. }
  52.  
  53. //========================================================================================
  54. // CLASS FW_CAcquireTemporarySystemHandle
  55. //========================================================================================
  56.  
  57. //----------------------------------------------------------------------------------------
  58. // FW_CAcquireTemporarySystemHandle::FW_CAcquireTemporarySystemHandle
  59. //----------------------------------------------------------------------------------------
  60.  
  61. FW_CAcquireTemporarySystemHandle::FW_CAcquireTemporarySystemHandle(unsigned long size) :
  62.     fTemporarySystemHandle(FW_CMemoryManager::AllocateSystemHandle(size))
  63. {
  64.     FW_TRY
  65.     {
  66.         fMemoryPointer = FW_CMemoryManager::LockSystemHandle(fTemporarySystemHandle);
  67.         fFree = TRUE;
  68.     }
  69.     FW_CATCH_BEGIN
  70.     FW_CATCH_EVERYTHING()
  71.     {
  72.         FW_CMemoryManager::FreeSystemHandle(fTemporarySystemHandle);
  73.         FW_THROW_SAME();
  74.     }
  75.     FW_CATCH_END
  76.     
  77.     FW_END_CONSTRUCTOR
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. // FW_CAcquireTemporarySystemHandle::~FW_CAcquireTemporarySystemHandle
  82. //----------------------------------------------------------------------------------------
  83.  
  84. FW_CAcquireTemporarySystemHandle::~FW_CAcquireTemporarySystemHandle(void)
  85. {
  86.     FW_START_DESTRUCTOR
  87.     
  88.     FW_CMemoryManager::UnlockSystemHandle(fTemporarySystemHandle);
  89.         
  90.     if(fFree)
  91.         FW_CMemoryManager::FreeSystemHandle(fTemporarySystemHandle);
  92. }
  93.  
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // FW_CAcquireTemporarySystemHandle::Resize
  97. //----------------------------------------------------------------------------------------
  98.  
  99. void FW_CAcquireTemporarySystemHandle::Resize(unsigned long newSize)
  100. {
  101.     // unlock the handle before resizing
  102.     FW_CMemoryManager::UnlockSystemHandle(fTemporarySystemHandle);
  103.     
  104.     // then resize it
  105.     FW_TRY
  106.     {
  107.         fTemporarySystemHandle =  FW_CMemoryManager::ResizeSystemHandle(fTemporarySystemHandle, newSize);
  108.     }
  109.     FW_CATCH_BEGIN
  110.     FW_CATCH_EVERYTHING()
  111.     {
  112.         // relock the handle
  113.         FW_CMemoryManager::LockSystemHandle(fTemporarySystemHandle);
  114.         FW_THROW_SAME();
  115.     }
  116.     FW_CATCH_END
  117.     
  118.     FW_CMemoryManager::LockSystemHandle(fTemporarySystemHandle);
  119. }
  120.  
  121. #ifdef FW_BUILD_MAC
  122. //========================================================================================
  123. // CLASS FW_CMacAcquireMultiFinderHeapZone
  124. //========================================================================================
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // FW_CMacAcquireMultiFinderHeapZone::FW_CMacAcquireMultiFinderHeapZone
  128. //----------------------------------------------------------------------------------------
  129.  
  130. FW_CMacAcquireMultiFinderHeapZone::FW_CMacAcquireMultiFinderHeapZone() :
  131.     fOldHeap(NULL)
  132. {
  133.     OSErr heapError;
  134.             
  135.     Handle heapTestHandle = ::TempNewHandle( 1, &heapError );
  136.     THz tempHeap = ::HandleZone( heapTestHandle );
  137.     heapError = ::MemError( );
  138.     ::DisposeHandle( heapTestHandle );
  139.     
  140.     if ( (heapError == noErr) && tempHeap ) {
  141.         fOldHeap = ::GetZone( );
  142.         ::SetZone( tempHeap );
  143.     }
  144.  
  145.     FW_END_CONSTRUCTOR
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. // FW_CMacAcquireMultiFinderHeapZone::~FW_CMacAcquireMultiFinderHeapZone
  150. //----------------------------------------------------------------------------------------
  151.  
  152. FW_CMacAcquireMultiFinderHeapZone::~FW_CMacAcquireMultiFinderHeapZone()
  153. {
  154.     FW_START_DESTRUCTOR
  155.     
  156.     if ( fOldHeap != NULL )
  157.         ::SetZone( fOldHeap );
  158. }
  159. #endif
  160.  
  161.  
  162.