Using char on variables
#1

All the examples I've seen on this forum about using a 8 bit variable, and from what I've read here, you cannot use negative values and you cannot go beyond the value 255 on using char arrays. Also that the char arrays use less bytes compared to normal variable (which is 4 bytes perhaps?) When I try to compile the script using a example variable: new maxy[MAX_PLAYERS char]; using -d3 compiler flag, it somehow gives the same data size and everything else as the same variable without char does. I think I'm doing something wrong. I haven't set the value for maxy afterwards because that's not essential, since bytes should be made when I create a variable.
Reply
#2

Slice explained how & what Char-Arrays for, I suggest you check this link this might solve your problem: https://sampforum.blast.hk/showthread.php?tid=216730
Reply
#3

test1.pwn
pawn Код:
#define FILTERSCRIPT

#include < a_samp >

new
    a[ 2000 ],
    b[ 2000 ],
    c[ 2000 ],
    d[ 2000 ],
    e[ 2000 ]
;

public OnFilterScriptInit( )
{
    for( new i; i != 2000; i++ )
    {
        a[ i ] = 200;
        b[ i ] = 200;
        c[ i ] = 200;
        d[ i ] = 200;
        e[ i ] = 200;
    }
    return 1;
}
pawn Код:
Header size:            116 bytes
Code size:              468 bytes
Data size:            40000 bytes // <--
Stack/heap size:      16384 bytes; estimated max. usage=9 cells (36 bytes)
Total requirements:   56968 bytes // <--
test1.amx -> size: 10,5 KB

---

test2.pwn
pawn Код:
#define FILTERSCRIPT

#include < a_samp >

new
    a[ 2000 char ],
    b[ 2000 char ],
    c[ 2000 char ],
    d[ 2000 char ],
    e[ 2000 char ]
;

public OnFilterScriptInit( )
{
    for( new i; i != 2000; i++ )
    {
        a{ i } = 200;
        b{ i } = 200;
        c{ i } = 200;
        d{ i } = 200;
        e{ i } = 200;
    }
    return 1;
}
pawn Код:
Header size:            116 bytes
Code size:              488 bytes
Data size:            10000 bytes // <--
Stack/heap size:      16384 bytes; estimated max. usage=9 cells (36 bytes)
Total requirements:   26988 bytes // <--
test2.amx -> size: 3,23 KB

---

You're now able to see huge difference!
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
test1.pwn
pawn Код:
#define FILTERSCRIPT

#include < a_samp >

new
    a[ 2000 ],
    b[ 2000 ],
    c[ 2000 ],
    d[ 2000 ],
    e[ 2000 ]
;

public OnFilterScriptInit( )
{
    for( new i; i != 2000; i++ )
    {
        a[ i ] = 200;
        b[ i ] = 200;
        c[ i ] = 200;
        d[ i ] = 200;
        e[ i ] = 200;
    }
    return 1;
}
pawn Код:
Header size:            116 bytes
Code size:              468 bytes
Data size:            40000 bytes // <--
Stack/heap size:      16384 bytes; estimated max. usage=9 cells (36 bytes)
Total requirements:   56968 bytes // <--
test1.amx -> size: 10,5 KB

---

test2.pwn
pawn Код:
#define FILTERSCRIPT

#include < a_samp >

new
    a[ 2000 char ],
    b[ 2000 char ],
    c[ 2000 char ],
    d[ 2000 char ],
    e[ 2000 char ]
;

public OnFilterScriptInit( )
{
    for( new i; i != 2000; i++ )
    {
        a{ i } = 200;
        b{ i } = 200;
        c{ i } = 200;
        d{ i } = 200;
        e{ i } = 200;
    }
    return 1;
}
pawn Код:
Header size:            116 bytes
Code size:              488 bytes
Data size:            10000 bytes // <--
Stack/heap size:      16384 bytes; estimated max. usage=9 cells (36 bytes)
Total requirements:   26988 bytes // <--
test2.amx -> size: 3,23 KB

---

You're now able to see huge difference!
char values are –128 | +127

#justsaying.
Reply
#5

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
char values are –128 | +127

#justsaying.
actually in PAWN, they're unsigned values from 0-255 (no negatives, -1 will wrap to 255)

#justsaying.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)