MySQL related question
#1

Well, I'm trying to convert Godfather's account system (fail ini functions) to MySQL, and I'm having a problem.

There are 76 fields at my user table. So I suppose I have to use:

pawn Код:
new Field[76][64]; //64 is the largest field size at my table
if(mysql_fetch_row(data))
{
    explode(Field, data, "|");
    //Blahblahblah
}
But when I do this, it increases my stack/heap size from (unknown because the pawn compiler doesn't show it, so it's good) to 49636 kb (the maximum is 16384). Obviously this happen because what the 'new' does is creating 76 variables with 64 cells.

If I place this Field[76][64] at the top of the string, no stack/heap message is produced.

Also, only one field is sized 64, the rest are integers (11) and a varchar (24).

So what should I do to split the fields? Place Field at the top of the script assuming it isn't overflowing the max stack/heap size or live with it using 76 mysql_fetch_field()?
Reply
#2

You array takes 76 * 64 * 4 Bytes = 19456 Bytes
And it seems that you are allocating even more data in that function thus the 49636 Bytes

Solutions
1. Increase the stack / heap size with #pragma dynamic cells (default 16 kB = 16384 B)
2. Use static which will saves the data globally (into the amx file)

If you want to reduce the allocated size you only need to find a better way than explode, maybe sscanf
Reply
#3

Use static at the top of the script or next to the function? People say #pragma dynamic doesn't solve memory problems
Reply
#4

Quote:
Originally Posted by hellangel
Посмотреть сообщение
Use static at the top of the script or next to the function? People say #pragma dynamic doesn't solve memory problems
You can use static like new, in your function, it is the same as a global variable just that it is limited to your function

Yes #pragma dynamic doesnt solve it, it just raises / lowers the dynamic memory space
Although I never saw any script with lowered the dynamic memory which the server allocates

People say that it doesnt save memory problems because they actually mean that this is a bad scripting habit which could be avoided by more advanced code, like in your situation
Reply
#5

Oh yeah, thanks dude... but what's the difference about static and new? I mean, why does new increase the stack and static don't?
Reply
#6

Quote:
Originally Posted by hellangel
Посмотреть сообщение
Oh yeah, thanks dude... but what's the difference about static and new? I mean, why does new increase the stack and static don't?
1. Global variables are always saved in the amx file
2. Local static variables are also saved in the amx file because they hold there value
3. Every other local variable will be created / destroyed while runtime in the dynamic memory block

The most information provided here can be found in the Pawn_Language_Guide.pdf
For profound things like the memory image check Pawn_Implementer_Guide.pdf
Reply
#7

may i ask smth?
so #pragma dynamic can cause lag?
Reply
#8

Normally not because most PC's nowadays got more than 16kb RAM

But its still one of the unnecessary things, if you want use higher amounts of data than use static or global variables
Reply
#9

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
You array takes 76 * 64 * 4 Bytes = 19456 Bytes
And it seems that you are allocating even more data in that function thus the 49636 Bytes

Solutions
1. Increase the stack / heap size with #pragma dynamic cells (default 16 kB = 16384 B)
2. Use static which will saves the data globally (into the amx file)

If you want to reduce the allocated size you only need to find a better way than explode, maybe sscanf
I have tried to use sscanf for doing this, but then I would need to specify ALL the arguments, wouldn't I? Like "siiiiiissiissisisisis" (Just an example, I know strings have sizes)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)