This wiki is out of date, use the continuation of this wiki instead

Memcmp

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 15:13, 13 May 2007 (edit)
Sandman (Talk | contribs)

← Previous diff
Current revision (12:46, 29 April 2008) (edit) (undo)
Sandman (Talk | contribs)
m
 
(2 intermediate revisions not shown.)
Line 6: Line 6:
Compares the first ''number'' bytes of the block of memory pointed by ''ptr1'' to the first ''number'' bytes pointed by ''ptr2'', returning zero if they all match or a value different from zero representing which is greater if they do not. Compares the first ''number'' bytes of the block of memory pointed by ''ptr1'' to the first ''number'' bytes pointed by ''ptr2'', returning zero if they all match or a value different from zero representing which is greater if they do not.
 +
 +''Available since [[Fenix]] version [[0.92]].''
== Parameters == == Parameters ==
Line 47: Line 49:
memset(pbyte1,3,elements); memset(pbyte1,3,elements);
memset(pbyte2,3,elements); memset(pbyte2,3,elements);
- result = memcmp(pbyte1,pbyte2,elements); // You can also compare the first 5 bytes, or the first elements/2 bytes,+ result = memcmp(pbyte1,pbyte2,elements); // You can also compare the first 5 bytes,
- // it depends on what you want.+ // or the first elements/2 bytes, it
 + // depends on what you want.
say("Memcmp 1: " + result); say("Memcmp 1: " + result);
Line 76: Line 79:
End End
</pre> </pre>
-Used in example: [[alloc]](), [[memset]](), [[say]](), [[free]](), [[pointer]]+Used in example: [[alloc]](), [[memset]](), [[memcmp]](), [[say]](), [[free]](), [[pointer]]
 + 
 +{{Funcbox
 + | category = Memory
 +}}

Current revision


Contents

[edit] Definition

INT memcmp ( <VOID POINTER ptr1> , <VOID POINTER ptr2> , <INT number> )

Compares the first number bytes of the block of memory pointed by ptr1 to the first number bytes pointed by ptr2, returning zero if they all match or a value different from zero representing which is greater if they do not.

Available since Fenix version 0.92.

[edit] Parameters

VOID POINTER ptr1 - Pointer to a block of memory
VOID POINTER ptr2 - Pointer to a block of memory.
INT number - The number of bytes to be checked.

[edit] Returns

INT : Difference

0 - The blocks of memory are identical.
>0 - The first differing byte in both memory blocks has a greater value in ptr1.
<0 - The first differing byte in both memory blocks has a greater value in ptr2.

A byte ranges from 0 to 255, meaning 189 is a greater value than 105.

[edit] Example

Program example;
Const
    elements = 10;
End
Private
    byte pointer pbyte1;
    byte pointer pbyte2;
    int result;
End
Begin

    // Allocate memory
    pbyte1 = alloc(elements);
    pbyte2 = alloc(elements);

    // Make the blocks the same and compare
    memset(pbyte1,3,elements);
    memset(pbyte2,3,elements);
    result = memcmp(pbyte1,pbyte2,elements); // You can also compare the first 5 bytes,
                                             // or the first elements/2 bytes, it
                                             // depends on what you want.
    say("Memcmp 1: " + result);

    // Make the first block have a greater value and compare
    pbyte1[0] = 4;
    result = memcmp(pbyte1,pbyte2,elements);
    say("Memcmp 2: " + result);

    // Make the blocks the same and compare
    pbyte2[0] = 4;
    result = memcmp(pbyte1,pbyte2,elements);
    say("Memcmp 3: " + result);

    // Make the first block have a greater value and compare
    pbyte2[1] = 5;
    result = memcmp(pbyte1,pbyte2,elements);
    say("Memcmp 4: " + result);

    Repeat
        frame;
    Until(key(_esc))

    // Free the used memory
    free(pbyte1);
    free(pbyte2);

End

Used in example: alloc(), memset(), memcmp(), say(), free(), pointer


Memory Functions
Alloc() • Free() • Memcmp() • Memcopy() • Memory_free() • Memory_total() • Memset() • Memsetw() • Realloc() •
Personal tools