Advantages/Disadvantages of using one string.
#1

Title pretty much says it all.

Let's say I have 100 multi-parameter commands in a huge roleplay mode, and in each command I would format a string to display a message. Now would it be efficient to just define one string to use in all the commands? I already know this would save tons of memory, but I read somewhere that Pawn is single-threaded.

For example

Player 1 types a command.
Player 2 types a command a few milliseconds after.

What are the chances of strings mixing up? Will that even happen?
Reply
#2

Do not do it, because besides outweigh the gamemode (in some cases), there may be problems with strcat, and strcmp because you would have to review all CODE's to clear the string, not to mention that there may be messages being sent to a id wrong with loops among other disadvantages.
Reply
#3

What do you mean by "outweigh" the gamemode?

How would there be problems with strcmp and strcat? I'm having a hard time understanding your post.
Reply
#4

Sorry, I'm using ****** Translator. The problem is that if you do not zero out the string, it will be with the old value (text), causing errors.
Reply
#5

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
What do you mean by "outweigh" the gamemode?

How would there be problems with strcmp and strcat? I'm having a hard time understanding your post.
Umm, to be honest I just use the same way like declaring only one variable "szFstring[ 128 ];" <- something similar and use it in all commands (small script, an include or maybe a filterscript) and I didn't had any kind of conflictions yet. I think it saves memory.

I was thinking to make a thread on this topic; thanks to you , at-least the confusion can be removed.

It would be good if someone well experienced in this situation give us a tip or something informative which correct us or just guide us if it is good to use in such way or declare the var for each command.

Regards,
FalconX
Reply
#6

Pawn is single threaded, which means that actions are executed one after the other. As long as you output the string right after you formatted it, there shouldn't be a problem. Yet I wonder why people are so obsessed with memory. Servers nowadays have several gigabytes of RAM. A sa-mp server will maybe use 100 megabytes at most.
Reply
#7

Not a lot of people running such a massive script have a hundred players or so to be for sure.

My main question is to how pawn functions. On top of a lot of callbacks being called, one can only expect a problem to arise when using one string for so many commands


EDIT

Quote:
Originally Posted by Vince
Посмотреть сообщение
Pawn is single threaded, which means that actions are executed one after the other. As long as you output the string right after you formatted it, there shouldn't be a problem. Yet I wonder why people are so obsessed with memory. Servers nowadays have several gigabytes of RAM. A sa-mp server will maybe use 100 megabytes at most.
That's what I was looking for, thank you. I'm not too worried about memory though, memory is not much of an issue on modern machines, just mainly concerned on optimization. I found it cool that some could compile a large mode in mere second. Learned something new today.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
As long as you output the string right after you formatted it, there shouldn't be a problem. .
I do not completly agree with this statement, as in any case of a small/short freeze and/or lag spike from the server, the strings would easily mix up.

I am using a new string for every command, just to make sure it doesn't mess up.
Reply
#9

Maybe use two or three strings? For example make command one with string1, make command two with string2, make command three with string3, then repeat?
Reply
#10

Quote:
Originally Posted by milanosie
Посмотреть сообщение
I do not completly agree with this statement, as in any case of a small/short freeze and/or lag spike from the server, the strings would easily mix up.

I am using a new string for every command, just to make sure it doesn't mess up.
from what iv read if their is only 1 thread then how would a freeze/lagg cause the string to mess up?
When the server becomes responsive then it SHOULD continue where it left off,
and no other functions will run until the last function returns "focus" to the chain.


@strcat problem

I do think the problem will be clearing the string properly (for some),
but i dont think thats a problem for you VD or anyone reading this topic.

i think somewhere was said the best method for it was string[0]='\0';
and if using in a remote function ect.. string[0]='\1',string[1]='\0';

iv been debating this "one global string" method myself, I want to make a single global string to use
for Query's, one for dialogs and one for TextDraws.
I will most likely start with the Sql Query's as the names are the
same in every function i have written for db access.


if you do run into trouble please let us know.
Reply
#11

I'll most definitely use this method with the SQL queries.

I mainly thought of this when I looked at the whole OnPlayerCommandText in the Godfather, that block of code was massive, and I saw the developer defined one string at the top of the callback. Since ZCMD just calls OnPlayerCommandText, you can use the same method.
Reply
#12

i see, and did not even consider this for commands, but now i think i might.
thx.

offtopic...
are you finally rewriting GF? haha j/k
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)