AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   charmax & sizeof (https://forums.alliedmods.net/showthread.php?t=214478)

GhostMan 04-27-2013 12:58

charmax & sizeof
 
In one 'Glow' plugin i found these lines:
PHP Code:

new name[64]
get_user_name(Player[iPlayer], namesizeof(name) -1

And i'm wondering if this would be the same?
PHP Code:

new name[33]
get_user_name(Player[iPlayer], namecharmax(name)) 

Maby using charmax is even better?

By the way would he creat name[64]? Aren't [33] is enought?

YamiKaitou 04-27-2013 13:21

Re: charmax & sizeof
 
charsmax is 100% identical to doing sizeof-1 seeing as it is macro for it

33 is plenty since a players name is only 32 characters long at most.

baneado 04-27-2013 17:59

Re: charmax & sizeof
 
charmax --> charsmax

one question, in this example it's better use 32 than charsmax?
you spare to call charsmax, a little better performance?

^SmileY 04-27-2013 18:05

Re: charmax & sizeof
 
Its a same thing, for example: charsmax(szName); or sizeof(szName) -1);
Its ready a max length of an string and count to -1.

Its working nice with a 32, 64, 128, 320 400 512 and all other size of Strings.

YamiKaitou 04-27-2013 18:23

Re: charmax & sizeof
 
charsmax (and I think sizeof as well) is replaced at compile, so there is no performance issue with using it

^SmileY 04-27-2013 18:41

Re: charmax & sizeof
 
Quote:

Originally Posted by YamiKaitou (Post 1941230)
charsmax (and I think sizeof as well) is replaced at compile, so there is no performance issue with using it

Its a macro replaced, not affect really a performace, and its more readable :)

Leon M. 04-28-2013 00:46

Re: charmax & sizeof
 
I never use charsmax for known array sizes anyways. More readable for me since you always get remembered how long the string can be :)

didoWEE 04-28-2013 04:43

Re: charmax & sizeof
 
if we have:
Code:

new string[20];
sizeof(string) will return 20
sizeof(string)-1 will return 19
charsmax(string) will return 19

That's everything you have to know

YamiKaitou 04-28-2013 06:59

Re: charmax & sizeof
 
Quote:

Originally Posted by Leon M. (Post 1941344)
I never use charsmax for known array sizes anyways. More readable for me since you always get remembered how long the string can be :)

And if you ever decide to change the length of the array, you must edit your file multiple times instead of just once

EpicMonkey 04-28-2013 09:26

Re: charmax & sizeof
 
Quote:

Originally Posted by YamiKaitou (Post 1941502)
And if you ever decide to change the length of the array, you must edit your file multiple times instead of just once

Exactly :3:3:3


All times are GMT -4. The time now is 10:46.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.