One new string[] for all script.
#1

Recently i had some problems with the size of my arrays. Pawno gave me this:

Код:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:           6428 bytes
Code size:           166072 bytes
Data size:           904192 bytes
Stack/heap size:      16384 bytes; estimated max. usage=10018 cells (40072 bytes)
Total requirements: 1093076 bytes
In order to avoid
pawn Код:
#pragma dynamic
i thought of using only one string for all the messages that needed format. So i did something like:
pawn Код:
new string[100];
and whenever i need to format a message that will be less than 100 characters i use this string. The problem with the size disappeared however I am concerned that this doesn't really change anything.
Is this going to reduce the memory used by the script and make the server lag less?
Reply
#2

Your script compiled fine, there is no worry here
Quote:

Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase

Reply
#3

It will be buggy at some instances, for example if u do something like this :
pawn Код:
SomeFunc(playerid) // lets say it is called at 01:25:00
{
format(string, sizeof(string), "something something");
for(new i = 0; i < 1000;i++)//lets say it takes 4 sec to complete this loop
SendClinetMessage(playerid, -1, string); // executed at 01:25:04 caz loops take 4sec
return 1;
}

SomeOtherFunc()// lets say it is called at 01:25:02
{
format(string, sizeof(string), "bla bla bla");
WriteFile("somefile.txt", string); // some imaginary function, clear with its name what it does
return 1;
}
So now SendClientMessage will send "bla bla bla" instead of what it was suppose to send
So don't do this, people don't create new strings at every function just for like that.
Reply
#4

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
It will be buggy at some instances, for example if u do something like this :
pawn Код:
SomeFunc(playerid) // lets say it is called at 01:25:00
{
format(string, sizeof(string), "something something");
for(new i = 0; i < 1000;i++)//lets say it takes 4 sec to complete this loop
SendClinetMessage(playerid, -1, string); // executed at 01:25:04 caz loops take 4sec
return 1;
}

SomeOtherFunc()// lets say it is called at 01:25:02
{
format(string, sizeof(string), "bla bla bla");
WriteFile("somefile.txt", string); // some imaginary function, clear with its name what it does
return 1;
}
So now SendClientMessage will send "bla bla bla" instead of what it was suppose to send
So don't do this, people don't create new strings at every function just for like that.
Ya you need to reset the string any time you use it.

Код:
mystring[0] = '\0';
Or something like this to make it easier to understand with something like

Код:
#define ResetString(%0) %0[0] = '\0'
Reply
#5

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
It will be buggy at some instances, for example if u do something like this :
pawn Код:
SomeFunc(playerid) // lets say it is called at 01:25:00
{
format(string, sizeof(string), "something something");
for(new i = 0; i < 1000;i++)//lets say it takes 4 sec to complete this loop
SendClinetMessage(playerid, -1, string); // executed at 01:25:04 caz loops take 4sec
return 1;
}

SomeOtherFunc()// lets say it is called at 01:25:02
{
format(string, sizeof(string), "bla bla bla");
WriteFile("somefile.txt", string); // some imaginary function, clear with its name what it does
return 1;
}
So now SendClientMessage will send "bla bla bla" instead of what it was suppose to send
So don't do this, people don't create new strings at every function just for like that.
You are right. But then how am i supposed to reduce the memory my script uses when i have to create strings of 100 cells size just to display a message?
Reply
#6

something like this -
pawn Код:
#undef MAX_PLAYERS  //default value is 500 i think
#define MAX_PLAYERS 50 //change it according to our needs
Do like this with MAX_VEHICLES too
Read this - https://sampforum.blast.hk/showthread.php?tid=57018
Reply
#7

I have already done that but it didn't seem to change something.
Reply
#8

change
#pragma dynamic
to
#pragma dynamic 10000
change it to higher value like 15000 if this doesnt work, and also make sure this is under include lines
Reply
#9

Looking to avoid #pragma dynamic.

Is it going to help if i create a function that will format the messages?
Something like
pawn Код:
#define FormattedMessage(..)
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
No, that won't help. You really shouldn't need that much stack space. The issue isn't really having large variables, but huge numbers of them. People who get this message frequently do things like declare five local strings when one would do. If a function has more than one local array then question it and refactor so it doesn't (not always possible of course, but frequently is). Global strings produce subtle issues.
And what if i really need to have big arrays in my script?
Arrays such as those that are going to be used for MySQL queries are requiring more than 500 cells. Is there any way to decrease the memory used without shorten the content of the strings?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)