home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 4.5 KB | 185 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLPriMem.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef SLPRIMEM_H
- #include "SLPriMem.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #define FW_OPENDOC 1
-
- #if FW_OPENDOC && defined(FW_BUILD_MAC)
- #include <MemMgr.h>
- #endif
-
- #if FW_OPENDOC && defined(FW_BUILD_WIN)
- #include <MMStubs.h>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
- #include <Windows.h>
- #endif
-
-
- #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWSX)
- #include <WindowsX.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__MEMORY__)
- #include <Memory.h>
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWCommon
- #endif
-
- #ifndef FW_USE_STANDARD_LIBRARY
- #define FW_USE_STANDARD_LIBRARY 1
- #endif
-
- #if FW_USE_STANDARD_LIBRARY
- #include <stdlib.h>
- #include <string.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveAllocateBlock
- //----------------------------------------------------------------------------------------
- void* FW_PrimitiveAllocateBlock(size_t n)
- {
- // No try block necessary - Do not throw
- #if FW_OPENDOC
- return ::MMAllocate(n);
- #elif defined(FW_BUILD_MAC)
- return ::NewPtr(n);
- #elif defined(FW_BUILD_WIN)
- return ::GlobalAllocPtr(GHND, n);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveResizeBlock
- //----------------------------------------------------------------------------------------
- void* FW_PrimitiveResizeBlock(void* p, size_t n)
- {
- // No try block necessary - Do not throw
- #if FW_OPENDOC
- return ::MMReallocate(p, n);
- #elif defined(FW_BUILD_MAC)
- void* q = p;
- if (q==NULL)
- q = ::FW_PrimitiveAllocateBlock(n);
- else
- {
- ::SetPtrSize((Ptr) q, n);
- if (::MemError() != noErr)
- {
- q = ::FW_PrimitiveAllocateBlock(n);
- if (q)
- {
- ::BlockMoveData(p, q, n);
- ::FW_PrimitiveFreeBlock(p);
- }
- }
- }
- return q;
- #elif defined(FW_BUILD_WIN)
- return ::GlobalReAllocPtr(p, n, 0);
- #endif
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveGetBlockSize
- //----------------------------------------------------------------------------------------
- size_t FW_PrimitiveGetBlockSize(void* p)
- {
- // No try block necessary - Do not throw
- #if FW_OPENDOC
- return ::MMBlockSize(p);
- #elif defined(FW_BUILD_MAC)
- return ::GetPtrSize((Ptr) p);
- #elif defined(FW_BUILD_WIN)
- return ::GlobalSize(GlobalPtrHandle(p));
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveFreeBlock
- //----------------------------------------------------------------------------------------
- void FW_PrimitiveFreeBlock(void* p)
- {
- // No try block necessary - Do not throw
- #if FW_OPENDOC
- if (p)
- ::MMFree(p);
- #elif defined(FW_BUILD_MAC)
- if (p)
- ::DisposePtr((Ptr) p);
- #elif defined(FW_BUILD_WIN)
- if (p)
- ::GlobalFreePtr(p);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveCopyMemory
- //----------------------------------------------------------------------------------------
-
- void FW_PrimitiveCopyMemory(const void *source, void *destination, size_t bytes)
- {
- // No try block necessary - Do not throw
-
- // This code must work correctly for overlapping blocks.
- #if defined(FW_BUILD_MAC)
- ::BlockMoveData(source, destination, bytes);
- #elif defined(FW_BUILD_WIN)
- ::MoveMemory(destination, source, bytes);
- #elif FW_USE_STANDARD_LIBRARY
- ::memmove(destination, source, bytes);
- #else
- if (source > destination)
- {
- char *dst = (char *) destination;
- const char *src = (const char *) source;
- while (bytes--)
- *dst++ = *src++;
- }
- else if (source < destination)
- {
- char *dst = (char *) destination + bytes;
- const char *src = (const char *) source + bytes;
- while (bytes--)
- *--dst = *--src;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveSetMemory
- //----------------------------------------------------------------------------------------
-
- void FW_PrimitiveSetMemory(void* block, size_t bytes, unsigned char value)
- {
- // No try block necessary - Do not throw
- #if FW_USE_STANDARD_LIBRARY
- ::memset(block, value, bytes);
- #else
- register unsigned char *p = (unsigned char*) block;
- while (bytes--)
- *p++ = value;
- #endif
- }
-
-