Skip to content

MemCopy

See Also: Memory Management Functions

Purpose

Copies data from one address to another.

Return Type

Boolean

Syntax

(MemCopy({pDest}, {pSource}, {iBytesToCopy}))

Where:

  • {pDest} is a Pointer variable that is the destination memory address.
  • {pSource} is a Pointer variable that is the source memory address.
  • {iBytesToCopy} is the number of bytes to copy.

What It Does

MemCopy copies a memory block from one address to another. You must specify valid addresses for pDest and pSource. They must be allocated before you use them. Improper use of the MemCopy function can cause your program to crash.

Example

This sample determines whether the MemCopy succeeded or not.

Move (Alloc(iLength)) to pDestination
Move (MemCopy(pDestination, pSource, iLength)) to bOk
If (Not(bOk)) Begin
    Error DFERR_PROGRAM "The MemCopy function failed"
End

This method can also be used to move contents of an address into a UChar array.

UChar[] ucFileData
Integer iResult iLength
Pointer aFileData
String sFileName
// ...
Direct_Input channel iChannel ("BINARY:" - sFileName)
If (not(SeqEof)) Begin
    Read_Block ucFileData -1
    Move (Base64Encode(AddressOf(ucFileData), SizeOfArray(ucFileData))) to aFileData
    Move (CStringLength(aFileData)) to iLength
    Move (ResizeArray(ucFileData, iLength, 0)) to ucFileData
    // ...
End
Move (MemCopy(AddressOf(ucFileData), aFileData, iLength)) to iResult