Bigger array size - more RAM consumption? -
zgintasz - 16.07.2012
Hi guys,
I have a very simple question. Does bigger array size uses more RAM consumption? Example:
pawn Код:
new
array1[ 2 ],
array2[ 2000 ]
;
So array1 uses less RAM consumption than array2?
And how to know, how much array1 or array2 uses RAM consumption(in bytes, kilobytes or megabytes)?
Re: Bigger array size - more RAM consumption? -
JernejL - 16.07.2012
Yes.
A pawn cell is 32 bit - 4 bytes, so if it's a global the script will use that memory pre-initialized in the amx file itself.
If it's a local, it will be added to the reserved stack portion, and everything ofcourse uses up ram..
Re: Bigger array size - more RAM consumption? -
zgintasz - 16.07.2012
Thanks! But I don't understand other thing. Did array used RAM size frees after using it? Example:
pawn Код:
public OnPlayerConnect( playerid )
{
new
array[ 2000 ]
;
// formating array, and doing something with it.
}
So connects 15 players. 15 * 2000 * 4 = 120000KB, so now the script uses 120000KB RAM? I'm sure it's not, so why listen
this tutorial instead of using example 256? It's just a 1KB

. Thanks for replies, I need arguments.
Re: Bigger array size - more RAM consumption? -
Vince - 16.07.2012
Yes, memory is freed as soon as the function ends. The thing is: why would you need the extra space if you're not going to use anyway? As JernejL already pointed out, there is a reserved stack portion to which all local variables are saved during function calls. If you use too much large arrays, the stack can eventually overflow and cause all kind of errors where variables overwrite each other.
Re: Bigger array size - more RAM consumption? -
zgintasz - 16.07.2012
Thanks a lot! If I can overflow the stack, what is the limit?
Re: Bigger array size - more RAM consumption? -
Vince - 16.07.2012
15 kilobytes or so, I believe. You can check that using the heapspace() native. The function returns the space left on the stack/heap in bytes, so you'll need to divide by 1024 to get kilobytes.
Re: Bigger array size - more RAM consumption? -
zgintasz - 16.07.2012
Thanks a lot for the info!