Defining a string
#1

So, I defined the strings in my commands at 256.

new string[256];


Is it too big and if so, what can it cause?
Reply
#2

I just asked this today,(https://sampforum.blast.hk/showthread.php?tid=30938&page=367).
Reply
#3

Make the string big enought for your format or whatever you want to use it
For ISmokezU format a 17 cells is enought, because there is 16 characters + the string termination
It's just a memory thing, how much memory to reserve for "string" , a 256cells (how you put) it's exactly 1024bytes
Not a big deal, don't worry about it unless you have to much much big strings (and their cells is not used ) than you can worry for memory leaks or to memeory using....
Reply
#4

Quote:
Originally Posted by Banditul18
Посмотреть сообщение
Make the string big enought for your format or whatever you want to use it
For ISmokezU format a 17 cells is enought, because there is 16 characters + the string termination
It's just a memory thing, how much memory to reserve for "string" , a 256cells (how you put) it's exactly 1024bytes
Not a big deal, don't worry about it unless you have to much much big strings (and their cells is not used ) than you can worry for memory leaks or to memeory using....
I use 256 at all of my commands, is this a issue? Example:


Код:
CMD:aann(playerid, params[])
{
	new string[256], message[128];
    if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_GREY, "You are not an admin!");
    if(sscanf(params, "s[128]", message)) return SCM(playerid, COLOR_GRAD2,"/aann <message>");
    format(string, sizeof(string), "STAFF ANNOUNCEMENT: {FFFFFF}%s", message);
	SendClientMessageToAll(COLOR_ORANGE, string);
	AdminLog(string);
	
	format(string, sizeof(string), "Announcement made by {FFFFFF}%s.", RPName(playerid));
	SendAdminMessage(COLOR_ORANGE, string);
	return 1;
}
Reply
#5

The maximum output for a client message is 144 characters, so in any case you're wasting almost half of it. If you can estimate the total length of the final output string then you should do so. In this particular case you can't because a player can input a text of any length.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)