home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 3.1 KB | 119 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPriMem.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/25/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #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
-
- //----------------------------------------------------------------------------------------
- // FW_PrimitiveAllocateBlock
- //----------------------------------------------------------------------------------------
- void* FW_PrimitiveAllocateBlock(size_t n)
- {
- #if 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)
- {
- #if defined(FW_BUILD_MAC)
- void* q = p;
- ::SetPtrSize((Ptr) q, n);
- if (MemError() != noErr)
- {
- q = FW_PrimitiveAllocateBlock(n);
- if (q)
- {
- ::BlockMove(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)
- {
- #if 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)
- {
- #if defined(FW_BUILD_MAC)
- if (p)
- ::DisposPtr((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)
- {
- #if defined(FW_BUILD_MAC)
- ::BlockMove(source, destination, bytes);
- #elif defined(FW_BUILD_WIN)
- // More efficient code is desirable. Don't want to use c standard library.
- // This code must work correctly for overlapping blocks.
- 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
- }