Raised This Month: $ Target: $400
 0% 

charmax & sizeof


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GhostMan
Senior Member
Join Date: Jun 2012
Old 04-27-2013 , 12:58   charmax & sizeof
Reply With Quote #1

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?

Last edited by GhostMan; 04-27-2013 at 12:59.
GhostMan is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-27-2013 , 13:21   Re: charmax & sizeof
Reply With Quote #2

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.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 04-27-2013 , 17:59   Re: charmax & sizeof
Reply With Quote #3

charmax --> charsmax

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

Last edited by baneado; 04-27-2013 at 18:08.
baneado is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 04-27-2013 , 18:05   Re: charmax & sizeof
Reply With Quote #4

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.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-27-2013 , 18:23   Re: charmax & sizeof
Reply With Quote #5

charsmax (and I think sizeof as well) is replaced at compile, so there is no performance issue with using it
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 04-27-2013 , 18:41   Re: charmax & sizeof
Reply With Quote #6

Quote:
Originally Posted by YamiKaitou View Post
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
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-28-2013 , 00:46   Re: charmax & sizeof
Reply With Quote #7

I never use charsmax for known array sizes anyways. More readable for me since you always get remembered how long the string can be
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015
Leon M. is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-28-2013 , 06:59   Re: charmax & sizeof
Reply With Quote #8

Quote:
Originally Posted by Leon M. View Post
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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
EpicMonkey
buttmonkey
Join Date: Feb 2012
Old 04-28-2013 , 09:26   Re: charmax & sizeof
Reply With Quote #9

Quote:
Originally Posted by YamiKaitou View Post
And if you ever decide to change the length of the array, you must edit your file multiple times instead of just once
Exactly
EpicMonkey is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 04-28-2013 , 16:24   Re: charmax & sizeof
Reply With Quote #10

Quote:
Originally Posted by YamiKaitou View Post
And if you ever decide to change the length of the array, you must edit your file multiple times instead of just once
A smart coder thinks earlier about it, changed once a variable and that was a quick edit. Well, only if you know what are you doing, so I guess its better to use charsmax

But that sounds conceited ;)

As I said such code is more readable for me, that's why I prefer it :p
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015
Leon M. is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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