I can just use a lower string?
#1

can i just use a lower string here?

PHP код:
new range,string[256];
format(stringsizeof(string), "AdmCmd: %s has disarmed all players within a range of : %d meters"PlayerData[playerid][Name],range); 
is it more optimized if the string is much lower?( was thinking to put it around 64)
Reply
#2

Why don't you use global string of size 1024/2000 instead of repeating string[X] on almost each like you'll need it ? On this code string size of 128 i'll be enough.
Reply
#3

Always, keep in mind that SA-MP's implementation of pawn has few limitations, especially when it comes to working with strings, the maximum input length is 128 characters long, as for the output, it's 144, this applies on client messages in particular.
Reply
#4

So, what's the best idea instead of doing global and only 1 string ?
Reply
#5

Quote:
Originally Posted by Hunud
Посмотреть сообщение
So, what's the best idea instead of doing global and only 1 string ?
Use local strings, don't ever create global variables unless the situation really calls for.
Reply
#6

Best idea (as mentioned indirectly above) is to keep local strings.

Also, it's a good habit making the string sizes as big as you need them, and not excessively big.
For the string above, we know that %s (playername) can't exceed the name-limit of 25 letters, and %d (as meters) will not exceed the limit of the script-defined range. Each number counts as 1 letter, and then we know the length of the entire string.

61 + 25 + 4 (i assume %d sholdn't need to exceed 9999) + 1 (plus one extra for the string-terminater) = 91.

You can safely shorten it down to 91.


However, these types of things doesn't mean the difference in terms of speeds or performance in small amounts. If you have a large script with many of those, then yes - it's smart to keep them short. No need to occupy space that you don't need.
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
Have you proven this code is the slowest part of your mode through profiling?



Because that's a terrible idea.
i`ve seen a lot of people saying dont use big strings and i was just wondering if lowering them is better for the script.

and thanks for the answers guys ! really appreciated
Reply
#8

Quote:
Originally Posted by PepsiCola23
Посмотреть сообщение
i`ve seen a lot of people saying dont use big strings and i was just wondering if lowering them is better for the script.

and thanks for the answers guys ! really appreciated
Yes, it is, each character takes up 1 cell, a cell is approximately 4 bytes, you do the math, you don't want to go around wasting memory, it may still be nothing compared to today standards, but it's always a good practice not to.
Reply
#9

http://siddharthamks.tk/wp-content/u...12/strlck.html
This will tell, you exact string value you need in your code.
Just add:
Quote:
Originally Posted by PepsiCola23
Посмотреть сообщение
PHP код:
AdmCmd: %s has disarmed all players within a range of : %d meters 
Also add +32 (for name limitation) and if you limit metres in two digits then add 2 and there you go with exact string..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)