One global string vs many small local strings
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

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

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)