Raised This Month: $51 Target: $400
 12% 

[Ask] String[] ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dias
BANNED
Join Date: Jul 2009
Location: South Vietnam
Old 03-09-2014 , 00:46   [Ask] String[] ?
Reply With Quote #1

A:
PHP Code:
new StringA[64// 64 
and

B:
PHP Code:
new StringB[] // 255 
So if i use B, it'll take more memory right ?
Correct me if i am wrong

Last edited by dias; 03-09-2014 at 00:46.
dias is offline
Send a message via Yahoo to dias Send a message via Skype™ to dias
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-09-2014 , 00:51   Re: [Ask] String[] ?
Reply With Quote #2

I honestly don't know what the default dimension is for arrays when not properly indexed when created but I highly recommend that you ALWAYS define the size of the array explicitly.
__________________
fysiks is offline
dias
BANNED
Join Date: Jul 2009
Location: South Vietnam
Old 03-09-2014 , 01:04   Re: [Ask] String[] ?
Reply With Quote #3

So A is better
dias is offline
Send a message via Yahoo to dias Send a message via Skype™ to dias
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-09-2014 , 01:16   Re: [Ask] String[] ?
Reply With Quote #4

Quote:
Originally Posted by dias View Post
So A is better
I wouldn't say it that way. I would say that A is the ONLY option.
__________________
fysiks is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 03-09-2014 , 03:37   Re: [Ask] String[] ?
Reply With Quote #5

X-Y Problem.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-09-2014 , 10:35   Re: [Ask] String[] ?
Reply With Quote #6

Quote:
Originally Posted by dias View Post
A:
PHP Code:
new StringA[64// 64 
and

B:
PHP Code:
new StringB[] // 255 
So if i use B, it'll take more memory right ?
Correct me if i am wrong
B won't even compile. Problem solved.
Code:
error 009: invalid array size (negative or zero)
error 036: empty statement
__________________

Last edited by Black Rose; 03-09-2014 at 10:37.
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-09-2014 , 16:53   Re: [Ask] String[] ?
Reply With Quote #7

Quote:
Originally Posted by Black Rose View Post
B won't even compile. Problem solved.
Code:
error 009: invalid array size (negative or zero)
error 036: empty statement
It seems to compile fine if you don't use the variable (which is what I tested originally) but when you actually use it, you'll get that error.
__________________

Last edited by fysiks; 03-09-2014 at 16:56.
fysiks is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-09-2014 , 16:59   Re: [Ask] String[] ?
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
It seems to compile fine if you don't use the variable (which is what I tested originally) but when you actually use it, you'll get that error.
If used globally, yes. If declared inside a function it will throw an error immediately.
__________________
Black Rose is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 03-10-2014 , 13:57   Re: [Ask] String[] ?
Reply With Quote #9

decl String:szName[] = "SmileY";

>> Create a String with char size
For sourcemod, for amxmodx do not have decl ??

EDIT:

new szName[] = "SmileY";

worked, but i do not know if it is a correct way, i think was created with a maximum lenght of 7 chars
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 03-10-2014 at 14:00.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-10-2014 , 14:15   Re: [Ask] String[] ?
Reply With Quote #10

Quote:
Originally Posted by ^SmileY View Post
decl String:szName[] = "SmileY";

>> Create a String with char size
For sourcemod, for amxmodx do not have decl ??

EDIT:

new szName[] = "SmileY";

worked, but i do not know if it is a correct way, i think was created with a maximum lenght of 7 chars
Easy way to find out:
server_print("Size of szName: %d", sizeof szName);
But yes, 6 chars + 1 null.
__________________

Last edited by Black Rose; 03-10-2014 at 14:15.
Black Rose is offline
Reply



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 12:17.


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