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

Which is more efficient? (CreateArray or multiple Arrays)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mitchell
~lick~
Join Date: Mar 2010
Old 11-12-2014 , 14:55   Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #1

I've been wonder, since i've used both and mixed for easily getting and setting data to use later on in the plugin. My question is really which is better to use?

Method 1: create an enum with large strings, ints, floats (vectors) and store it in a CreateArray.
Method 2: create an Array for each of the values with a MAX.

Note: this will store entities, that will later be saved to a file to be easily loaded back again (key values) So every time an entity is created, it will either be pushed at the end of the array or counted up by one. This will also be sorted, so each prop will load in order. Each player will also have an array, but they won't necessarily be using it, or if they are using it they might not have a lot of entities owned.

Note 2: This is what i'm talking about with enum and CreateArray: https://bitbucket.org/MitchDizzle/su...t=master#cl-17
and https://bitbucket.org/MitchDizzle/su...=master#cl-134

Wow, wrong section. lol

Last edited by Mitchell; 11-12-2014 at 14:59.
Mitchell is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 11-12-2014 , 15:47   Re: Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #2

dynamic arrays are always slower but it not like if it matter that much, I've been using method 1 for 2 years so far in all of my projects and it really helpful. I create my header file with my enum structs and when ever I need a new var for a player or what ever I just go in my header and add the var into the enum. With global variable, you can get lost when you working on large scaled projects.

It sure up to you. Readability is always a good option but yea you need to use them right also.

You can also easily write binary file (saves) of your structures. For example if you have a structure to save points in the maps that you want to load on map change you can load/save the file binary which is really fast and unreadable or un-usable except if someone know your structure and your structure order.

EDIT: Oh lol, I did not finished to read your post and did not see the note, yea well structures are the way to go with binary file except if you like to edit the files manually. Other wise you can create some access point in your mod to change the value and save them if you want to edit it manually. OOP in sourcepawn lol, rare but it possible.

Last edited by Mathias.; 11-12-2014 at 15:53.
Mathias. is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-12-2014 , 16:04   Re: Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #3

Black-Rabbit, thanks for the input. I'm half tempted to go with the dynamic array.
The data stored will be used for a separate plugin as one will be used for the users to create entities, and the other one will be used to generate out what is saved in the file.
The only times this array will be used is when it loads/saves from FileIO and when an entity is edited/added/removed
Mitchell is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 11-12-2014 , 16:07   Re: Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #4

alrite good luck with your project , if you need help with the binary file, I don't mind give you an example.
Mathias. is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-12-2014 , 16:35   Re: Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #5

Quote:
Originally Posted by Black-Rabbit View Post
alrite good luck with your project , if you need help with the binary file, I don't mind give you an example.
Thank you! I'll probably stick with kayvalues, for now anyways.
Mitchell is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 11-12-2014 , 22:08   Re: Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #6

I always use dynamic arrays, unless there is too much data and I need expadabable containers, then I just use keyvalues and keep the KV open...

Usually dynamic arrays are pretty easy/fast to iterate anyways.
If you are doing something where you don't know how many elements there may be (or it's not important to know, and you just want to iterate until you find what you're after) you can just use a linked list. Likewise, with all these racing plugins for tf2, might be a good idea to make a linked list out of the tracks.. or not. Whatever floats your boat.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-12-2014 , 22:17   Re: Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #7

Quote:
Originally Posted by friagram View Post
Likewise, with all these racing plugins for tf2, might be a good idea to make a linked list out of the tracks.. or not. Whatever floats your boat.
you caught me But that's not going to be my approach, as i would rather store the it as a checkpoint (so i can add boosts with the same checkpoint number later on)

but i guess i was thinking too much ahead, i would only need to store a few things in an array (the checkpoint of the track piece and any other attributes i decide to add after i build the base.

Last edited by Mitchell; 11-12-2014 at 22:20.
Mitchell is offline
API
Veteran Member
Join Date: May 2006
Old 11-13-2014 , 12:11   Re: Which is more efficient? (CreateArray or multiple Arrays)
Reply With Quote #8

ADT all day. Source: og convos with bail back in the day
__________________
API is offline
Send a message via AIM to API
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 23:00.


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