These functions are used to be able to perform pointer operations in EbsScript, as they are common e.g. in the C programming language.
The declaration of a pointer (a reference) is done by "^" in front of the type name.
The address of a variable is accessed by a "&" in front of the variable name.
The content of the address to which the pointer refers (i.e. the value stored there) can be accessed by placing a "^" after the pointer variable (dereferencing).
A variable of type pointer contains the memory address of a variable of a certain type (like integer, real...).
Simple example:
var realnumber : real;
pointertoreal : ^real;
pointertype : pointer;
begin
realnumber := 7.0;
pointertoreal := &realnumber;
println ("using ^ on pointer: ", pointertoreal^ * pointertoreal^);
pointertype := pointertoreal;
pointertoreal^ := 8;
println ("Square: ", realnumber * realnumber);
end.
Ausgabe:
using ^ on pointer: 49.0
Square: 64.0
Name |
Purpose |
Arguments |
Return value |
Example |
copymem |
copies a memory area. size = number of elementary data types. |
1: POINTER: Destination 2: POINTER: Source 3: INTEGER: Size |
None |
|
dispose |
releases the memory area again, which was allocated by function new to the object, to which the pointer indicates. |
1: POINTER: |
None |
var pi:^integer;
begin new(pi); pi^:=5; print (pi^); dispose(pi); end; |
freemem |
releases the memory area again, which was allocated by function getmem to the object, to which the pointer indicates. |
1: POINTER: |
None |
|
getmem |
creates a new pointer and allocates the necessary memory for the object, to which the pointer indicates. Count > 1: array of elements |
1: POINTER: |
None |
|
new |
creates a new pointer and allocates the necessary memory for the object, to which the pointer indicates. Count > 1: array of elements |
1: POINTER: |
None |
var pi:^integer;
begin new(pi); pi^:=5; print (pi^); dispose(pi); end; |
sizeOf |
Returns size of the Object or Variable |
Type of object or variable |
INTEGER |
var i: integer; |
addr |
Returns the address of the argument. |
variable |
INTEGER |
var i: integer; |