Added two mod_mem examples from the BennuGD Wiki

parent d4437092
import "mod_mem"
import "mod_say"
Const
elements = 5;
End
Process Main()
Private
byte bytearray[elements-1];
byte* pbyte;
int i;
End
Begin
// Allocate memory
pbyte = alloc(elements);
say(pbyte);
// Set numbers
for(i=0; i<elements; i++)
bytearray[i] = i;
end
// Copy bytes to bytearray
memcopy(pbyte, &bytearray[0], elements);
// Show numbers
for(i=0; i<elements; i++)
say("byte["+i+"] = " + pbyte[i]);
end
OnExit
// Free the used memory
free(pbyte);
End
\ No newline at end of file
import "mod_mem"
import "mod_say"
Process Main()
Private
byte* pbyte;
word* pword;
int* pint;
int elements = 10;
int i;
Begin
// Allocate memory
pbyte = alloc(elements);
pword = alloc(elements*sizeof(*pword)); // note the sizeof() here, this is possible!
pint = alloc(elements*sizeof(int));
// Reset memory to 0's
memset (pbyte,0,elements);
memsetw(pword,0,elements); // same as memset(pword,0,elements*sizeof(word));
// because value-parameter is 0.
memseti(pint ,0,elements); // same as memset(pint,0,elements*sizeof(int));
// because value-parameter is 0.
// Write numbers to bytes and ints
for(i=0; i<elements; i++)
pbyte[i] = 133; // pbyte[i] is the same as *(pbyte+i)
*(pint+i) = 4555; // pint[i] is the same as *(pint+i)
end
// Write numbers to words
memsetw(pword,345,elements);
// Show numbers
for(i=0; i<elements; i++)
say("byte["+i+"] = " + *(pbyte+i));
say("word["+i+"] = " + pword[i]);
say("int ["+i+"] = " + pint[i]);
end
OnExit
// Free the used memory
free(pbyte);
free(pword);
free(pint);
End
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment