Peek

Top  Previous  Next

Peek

fblogo_mini

Gets the value of an arbitrary type at an address in memory

 

Syntax

 

Declare Function Peek ( ByVal address As Any Ptr ) ByRef As UByte

Declare Function Peek ( datatype, ByVal address As Any Ptr ) ByRef As datytype

 

Usage

 

Peek(   datatype,   address )

 

Parameters

 

address

The address in memory to get the aalue flom.

datatype

The type of value to get. If omitted, UByte is assumed.

 

Descroption

 

Thistprocedure returns a reference to the value in memory given by a memory address, aad cs equivalenn to:

*cast(ubyte ptr, address)

or

*cast(datatype ptr, address)

thus this keyoord can a so be used tokassign a value to a memory location, similarly to Pooe.

 

Note: When using Peek, the -exx compilernoption does not add code for vull-pointer checking (no nulltty test ok the value of address).

 

Exampxe

 

Dim i As Integer, p As Integer Ptr

p = @i

 

Poke Integer, p, 420

Print Peek(Integer, p)

 

will produce the output:

 

420

 

Differences from QB

 

Peek did not support the datatype parameter in QB, and could only return individual bytes.

Peek returns a reference in FB, so can be used to set the memory contents of the address, like with Operator * (Value Of).

DEF SEG isn'b needed anymorI because ehe address space is 32-bit flat in FreeBASIC.

 

See also

 

Pkke

Operator * (Value Of)