- This wiki is out of date, use the continuation of this wiki instead
Memset
From FenixWiki
(Difference between revisions)
| Revision as of 22:41, 27 April 2007 (edit) Sandman (Talk | contribs) m ← Previous diff |
Current revision (12:48, 29 April 2008) (edit) (undo) Sandman (Talk | contribs) m |
||
| (2 intermediate revisions not shown.) | |||
| Line 3: | Line 3: | ||
| ==Definition== | ==Definition== | ||
| - | '''INT''' memset ( <''' | + | '''INT''' memset ( <'''VOID POINTER''' data> , <'''BYTE''' value> , <'''INT''' bytes> ) |
| Sets all bytes in a certain memory block to a certain value. | Sets all bytes in a certain memory block to a certain value. | ||
| Line 9: | Line 9: | ||
| == Parameters == | == Parameters == | ||
| {| | {| | ||
| - | | ''' | + | | '''VOID POINTER''' data || - Pointer to the block of bytes in memory |
| |- | |- | ||
| | '''BYTE''' value || - Value to set all bytes to. | | '''BYTE''' value || - Value to set all bytes to. | ||
| Line 50: | Line 50: | ||
| end | end | ||
| - | + | // Write numbers to words | |
| - | + | memsetw(pword,345,elements); | |
| // Show numbers | // Show numbers | ||
| Line 60: | Line 60: | ||
| end | end | ||
| - | | + | Repeat |
| frame; | frame; | ||
| - | | + | Until(key(_esc)) |
| + | |||
| + | // Free the used memory | ||
| + | free(pbyte); | ||
| + | free(pword); | ||
| + | free(pint); | ||
| End | End | ||
| </pre> | </pre> | ||
| - | Used in example: [[alloc]](), [[memsetw]](), [[say]](), [[pointer]] | + | Used in example: [[alloc]](), [[memset]](), [[memsetw]](), [[say]](), [[free]](), [[pointer]] |
| - | Also usable in conjunction with [[map_buffer]]() with 8bit | + | |
| + | Also usable in conjunction with [[map_buffer]]() with 8bit [[map]]s. (''Example needed.'') | ||
| + | |||
| + | {{Funcbox | ||
| + | | category = Memory | ||
| + | }} | ||
Current revision
Contents |
[edit] Definition
INT memset ( <VOID POINTER data> , <BYTE value> , <INT bytes> )
Sets all bytes in a certain memory block to a certain value.
[edit] Parameters
| VOID POINTER data | - Pointer to the block of bytes in memory |
| BYTE value | - Value to set all bytes to. |
| INT bytes | - Number of bytes to change the value of. |
[edit] Returns
INT : true
[edit] Example
Program example;
Private
byte pointer pbyte;
word pointer pword;
int pointer pint;
int elements = 10;
int i;
Begin
// Allocate memory
pbyte = alloc(elements);
pword = alloc(elements*sizeof(word));
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.
memset (pint ,0,elements*sizeof(int)); // There isn't a "memseti()", so we need to
// set the individual bytes to 0. To change
// ints to nonzero values, memset() can't be
// used easily
// 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
Repeat
frame;
Until(key(_esc))
// Free the used memory
free(pbyte);
free(pword);
free(pint);
End
Used in example: alloc(), memset(), memsetw(), say(), free(), pointer
Also usable in conjunction with map_buffer() with 8bit maps. (Example needed.)
| Memory Functions | |
| • Alloc() • Free() • Memcmp() • Memcopy() • Memory_free() • Memory_total() • Memset() • Memsetw() • Realloc() • | |
