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

ArrayList size difference


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 03-13-2019 , 13:46   ArrayList size difference
Reply With Quote #1

what's the difference?
ArrayList[MAXPLAYERS + 1] PlayerInfo;
vs
ArrayList PlayerInfo[MAXPLAYERS + 1];

both works well
__________________
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-13-2019 , 14:18   Re: ArrayList size difference
Reply With Quote #2

I'm surprised that ArrayList[MAXPLAYERS + 1] is even allowed as only dynamically sized array are supposed to support brackets after the type according to the docs.

i.e.

PHP Code:
ArrayList[] PlayerInfo = new ArrayList[MaxClients 1]; 
vs.
PHP Code:
ArrayList PlayerInfo[MAXPLAYERS 1]; 
Note that the first would only work inside a method, although you could split it into two parts, like so:

PHP Code:
ArrayList[] PlayerInfo;

//in a method such as OnMapStart
if (PlayerInfo != null)
    
delete PlayerInfo;

PlayerInfo = new ArrayList[MaxClients 1]; 
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-13-2019 at 14:24.
Powerlord is offline
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 03-13-2019 , 14:52   Re: ArrayList size difference
Reply With Quote #3

I using this

PHP Code:
ArrayList[MAXPLAYERS 1PlayerInfo;

    for(
int i 1<= MaxClientsi++)
        
PlayerInfo[i] = new ArrayList(5); 
__________________

Last edited by _GamerX; 03-13-2019 at 14:52.
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 03-15-2019 , 09:03   Re: ArrayList size difference
Reply With Quote #4

Quote:
Originally Posted by _GamerX View Post
I using this

PHP Code:
ArrayList[MAXPLAYERS 1PlayerInfo;

    for(
int i 1<= MaxClientsi++)
        
PlayerInfo[i] = new ArrayList(5); 
MAXPLAYERS is a constant value, so I do not see any purposes of creating an array with dynamic length.
Just create fixed-length array.
PHP Code:
ArrayList PlayerInfo[MAXPLAYERS 1]; //Global variable

void OnPluginStart()  //Or somewhere else
{
    for(
int i 1<= MaxClientsi++)
    {
        
PlayerInfo[i] = new ArrayList(5);
    }


Last edited by impossible_cc; 03-15-2019 at 09:09.
impossible_cc is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-19-2019 , 03:29   Re: ArrayList size difference
Reply With Quote #5

Quote:
Originally Posted by _GamerX View Post
I using this

PHP Code:
ArrayList[MAXPLAYERS 1PlayerInfo;

    for(
int i 1<= MaxClientsi++)
        
PlayerInfo[i] = new ArrayList(5); 

What version of the compiler are you using? This does not compile for me in any of 1.7, 1.8, 1.9, or 1.10.
Fyren 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:10.


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