Using char on variables - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Using char on variables (
/showthread.php?tid=477470)
Using char on variables -
||123|| - 24.11.2013
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.
Re: Using char on variables - Patrick - 24.11.2013
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
Re: Using char on variables -
Konstantinos - 24.11.2013
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!
Re: Using char on variables -
Djole1337 - 24.11.2013
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.
Re: Using char on variables -
Ada32 - 24.11.2013
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.