Using single global variable for formatting text
#1

Hello, I have one question about functionality of above.

Instead of creating a string in every single public/function, I have declared one global variable as an array, which I used basicly everywhere I want to format and display some text for certain player.

And my question is, when for example will get something executed for player X, where's global string is being processed, meanwhile player Y need that variable too, will server wait till player X is processed or not?

Becouse I'm afraid of some disruption in this, if for example more players executed a piece of code where global string is being processed.

Actually, if server would wait till code called will get processed, it should be working properly, but I'm not sure about how it does.
Reply
#2

When something being processed server will wait until it finish except if its threaded....
however I don't suggest using a global string for everything.
I had that once and random messages were being sent wrongly. then had to take rid of that...
Reply
#3

As long as now I read SA:MP server is single threaded, it should be working fine in all cases.
You sure, that your code was written properly before?
Reply
#4

There is no need to do such bullshit :
Reply
#5

It has noticably great impact on compilation time, so on the final amx size. Don't know, why it should be such bullshit.
Reply
#6

As jlalt said, messages can be mixed up.
Reply
#7

I'd recommend you to keep it as a local variable.
Reply
#8

Declare it as:
PHP код:
new pStrings[MAX_PLAYERS][MAX_STRINGS_PER_PLAYER][MAX_STRING_LENGTH]; 
Reply
#9

Quote:
Originally Posted by Paulice
Посмотреть сообщение
Declare it as:
PHP код:
new pStrings[MAX_PLAYERS][MAX_STRINGS_PER_PLAYER][MAX_STRING_LENGTH]; 
This pains my eyes. Avoid globals where you can. "The size of the amx" is an irrelevant argument. Should be a couple megabytes tops; the size of an average picture or song.
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
This pains my eyes. Avoid globals where you can. "The size of the amx" is an irrelevant argument. Should be a couple megabytes tops; the size of an average picture or song.
That's something he can go with (if he insists to go forward with his idea). My only doubt is if using global variables reduces compile time (as he states) to a considerable extent?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)