Originally Posted by Slice
"Char-arrays"PAWN has a feature for accessing single bytes in arrays, intended for use with packed strings. Most SA-MP natives doesn't cover packed strings, though.
You can, however, utilize these arrays a lot for memory optimization. A normal array can store values between -2,147,483,648 and 2,147,483,647; you don't always need that capacity, do you?
With packed strings you can store values between 0-255 (yes, no negative values; -1 will wrap to 255). When you know you don't need negative values and won't ever exceed 255, why not save some memory?
pawn Код:
new bool:g_IsPlayerSomething[ MAX_PLAYERS ]; // 500 cells * 4 bytes per cell = 2000 bytes! new bool:g_IsPlayerSomething[ MAX_PLAYERS char ]; // 500 bytes = .. 500 bytes!
If you use "char arrays" instead of normal ones where needed 50 times you'll save 75,000 bytes (~73 kb).
Note!
When accessing these arrays, you need to use curly brackets (aka braces) as opposed to the normal square brackets.
Example:
pawn Код:
public OnPlayerConnect( playerid ) { g_IsPlayerSomething{ playerid } = false; // ^ ^ }
public OnPlayerSpawn( playerid ) { // v v if ( g_IsPlayerSomething{ playerid } ) { // .. } }
|