You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.
Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.
set window on : set window layout 0,0,0 : set window position 0,0 : set display mode desktop width(),desktop height(),32
FOR C = 1 TO 23
LinesOfText$(C) = ""
GLOBAL DIM LinesOfText$(23)
// some examples of alloc, realloc, poke string, peek string and free
pointer=alloc(0) //allocates 1 byte and returns the pointer.
// if the pointer is 0, the system could not allocate free memory and the pointer is invalid. writing to an invalid pointer will crash the programm.
pointer=realloc(pointer,1) // still 1 byte, probabaly on another position
pointer=realloc(pointer,2) // 2 bytes, most likely on another position.
// let's say you want to write a string:
s1$="Hallo Welt1" // german for Hello World
length1=len(s1$)+1 // a string in written by poke string normaly ends with a 0
length2=len(s2$)+1 // a string in written by poke string normaly ends with a 0
pointer=realloc(pointer,length1+length2) // realloc with the size of both strings.
poke string pointer,s1$ // poke at the start of the string
poke string pointer+length1,s2$ // poke at the start of the second string
// what is now in memory:
// 48 61 6C 6C 6F 20 57 65 6C 74 31 00 48 61 6C 6C 6F 20 57 65 6C 74 32 00
// H a l l o W e l t 1 H a l l o W e l t 2
print peek string(pointer)
print peek string(pointer+length1)
free pointer // always free the memory before you close the programm
Login to post a reply