SA-MP Forums Archive
One global string vs many small local strings - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: One global string vs many small local strings (/showthread.php?tid=375180)



One global string vs many small local strings - zgintasz - 05.09.2012

Hi guys,

Which variant is better, making one global string and using it everywhere where I need one string variable or creating local string variable in every function? In code, it'll look like this:

pawn Код:
//first
new
    global_string[ 1024 ] // or maybe bigger
;
public OnGameModeInit( )
{
    format( global_string, sizeof( global_string ), "blablabla, %d", 0 );
    DoSomething( global_string );
}

public OnPlayerConnect( playerid )
{
    format( global_string, sizeof( global_string ), "blablabla, %d", 0 );
    DoSomething( global_string );
}
//and etc...

// second

public OnGameModeInit( )
{
    new
        string[ 50 ]
    ;
    format( string, sizeof( string ), "blablabla, %d", 0 );
    DoSomething( string );
}

public OnPlayerConnect( playerid )
{
    new
        another_string[ 50 ]
    ;
    format( another_string, sizeof( another_string ), "blablabla, %d", 0 );
    DoSomething( another_string );
}
// and etc...
And of course I want to know why is it better .

Thanks.


Re: One global string vs many small local strings - mobiliz - 05.09.2012

If you create different strings it wont really effect the game you, but you can keep doing like new string[128]; not like new another_string[128]; can you just use new string[128]; every time, If you just use one big string it might make your life easier so you don't need to keep doing new but maybe some problems may occur if you use the big string everytime.

So I think doing new string[128]; is kinda more reliable.


Re: One global string vs many small local strings - zgintasz - 05.09.2012

Variable names was just a example, what about memory consumption? Pawn is single threaded, so I don't really agree with this:

Quote:
Originally Posted by mobiliz
Посмотреть сообщение
but maybe some problems may occur if you use the big string everytime.



Re: One global string vs many small local strings - mobiliz - 05.09.2012

Why don't you test which is the best for your-self then?


Re: One global string vs many small local strings - ryansheilds - 05.09.2012

I don't think there would be much difference if not none at all. Since PAWN is single threaded there shouldn't be any strings override, I guess it's which you prefer.