Core Function Alloc
From Sputnik Wiki
(Difference between revisions)
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | Alloc( <size>, < | + | Alloc( <size>, <filler> ) |
</pre> | </pre> | ||
Line 13: | Line 13: | ||
Size in bytes to allocate. | Size in bytes to allocate. | ||
− | ==== | + | ==== filler ==== |
− | Optional; If | + | Optional; If filler is given it will be used to preset all the bytes allocated to this number. |
+ | |||
+ | Usually used to zero all the data during allocation. | ||
=== Return Value === | === Return Value === | ||
Line 31: | Line 33: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
$PTR = Alloc(300); | $PTR = Alloc(300); | ||
+ | //$PTR = Alloc(300, 0x00); // All allocated data will be zeroed 0x00 | ||
PTRWrite($PTR, "f", 0, 133.77); | PTRWrite($PTR, "f", 0, 133.77); |
Revision as of 06:39, 22 August 2013
Alloc( <size>, <filler> )
Contents |
Description
Allocate memory and return the pointer to it.
Parameters
size
Size in bytes to allocate.
filler
Optional; If filler is given it will be used to preset all the bytes allocated to this number.
Usually used to zero all the data during allocation.
Return Value
Success: Returns a valid pointer.
Failure: Returns 0.
Remarks
Using alloc etc its even possible to create your own memory based functions such as your own DLLStruct functions.
Example
$PTR = Alloc(300); //$PTR = Alloc(300, 0x00); // All allocated data will be zeroed 0x00 PTRWrite($PTR, "f", 0, 133.77); PTRWrite($PTR, "l", 4, 777); PTRWrite($PTR, "i", 12, 1221); Println( PTRRead($PTR, "f", 0) ); Println( PTRRead($PTR, "l", 4) ); Println( PTRRead($PTR, "i", 12) ); Free($PTR);