home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.0 KB | 162 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWMemHlp.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWMemory
- #endif
-
- //========================================================================================
- // class FW_CAcquireLockedSystemHandle
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireLockedSystemHandle::FW_CAcquireLockedSystemHandle
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireLockedSystemHandle::FW_CAcquireLockedSystemHandle(FW_PlatformHandle aSystemHandle)
- : fLockedSystemHandle(aSystemHandle),
- fLockedPointer(FW_CMemoryManager::LockSystemHandle(aSystemHandle))
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireLockedSystemHandle::~FW_CAcquireLockedSystemHandle
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireLockedSystemHandle::~FW_CAcquireLockedSystemHandle()
- {
- FW_START_DESTRUCTOR
- FW_CMemoryManager::UnlockSystemHandle(fLockedSystemHandle);
- }
-
- //========================================================================================
- // CLASS FW_CAcquireTemporarySystemHandle
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireTemporarySystemHandle::FW_CAcquireTemporarySystemHandle
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireTemporarySystemHandle::FW_CAcquireTemporarySystemHandle(unsigned long size) :
- fTemporarySystemHandle(FW_CMemoryManager::AllocateSystemHandle(size))
- {
- FW_TRY
- {
- fMemoryPointer = FW_CMemoryManager::LockSystemHandle(fTemporarySystemHandle);
- fFree = TRUE;
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- FW_CMemoryManager::FreeSystemHandle(fTemporarySystemHandle);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireTemporarySystemHandle::~FW_CAcquireTemporarySystemHandle
- //----------------------------------------------------------------------------------------
-
- FW_CAcquireTemporarySystemHandle::~FW_CAcquireTemporarySystemHandle(void)
- {
- FW_START_DESTRUCTOR
-
- FW_CMemoryManager::UnlockSystemHandle(fTemporarySystemHandle);
-
- if(fFree)
- FW_CMemoryManager::FreeSystemHandle(fTemporarySystemHandle);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireTemporarySystemHandle::Resize
- //----------------------------------------------------------------------------------------
-
- void FW_CAcquireTemporarySystemHandle::Resize(unsigned long newSize)
- {
- // unlock the handle before resizing
- FW_CMemoryManager::UnlockSystemHandle(fTemporarySystemHandle);
-
- // then resize it
- FW_TRY
- {
- fTemporarySystemHandle = FW_CMemoryManager::ResizeSystemHandle(fTemporarySystemHandle, newSize);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- // relock the handle
- FW_CMemoryManager::LockSystemHandle(fTemporarySystemHandle);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- FW_CMemoryManager::LockSystemHandle(fTemporarySystemHandle);
- }
-
- #ifdef FW_BUILD_MAC
- //========================================================================================
- // CLASS FW_CMacAcquireMultiFinderHeapZone
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CMacAcquireMultiFinderHeapZone::FW_CMacAcquireMultiFinderHeapZone
- //----------------------------------------------------------------------------------------
-
- FW_CMacAcquireMultiFinderHeapZone::FW_CMacAcquireMultiFinderHeapZone() :
- fOldHeap(NULL)
- {
- OSErr heapError;
-
- Handle heapTestHandle = ::TempNewHandle( 1, &heapError );
- THz tempHeap = ::HandleZone( heapTestHandle );
- heapError = ::MemError( );
- ::DisposeHandle( heapTestHandle );
-
- if ( (heapError == noErr) && tempHeap ) {
- fOldHeap = ::GetZone( );
- ::SetZone( tempHeap );
- }
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMacAcquireMultiFinderHeapZone::~FW_CMacAcquireMultiFinderHeapZone
- //----------------------------------------------------------------------------------------
-
- FW_CMacAcquireMultiFinderHeapZone::~FW_CMacAcquireMultiFinderHeapZone()
- {
- FW_START_DESTRUCTOR
-
- if ( fOldHeap != NULL )
- ::SetZone( fOldHeap );
- }
- #endif
-
-
-