View Single Post
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-09-2014 , 16:29   Re: [ TUT ]Dynamic Array
Reply With Quote #7

Some thoughts:

Quote:
Arrays are homogenous containers
If I don't say bullshits, in dev build, it's now heterogeneous. Same as Trie. Both internal libraries have been completely replaced by the libraries from SourceMod.

Quote:
tries and dyn arrays are very slow on data insertion
This should be relativized. No that slow. It could have been true with Trie, but in dev build, since it uses hashmap now, speed has been drastically improved. About Array, insertion is just about something like array[count++] = cell ; that's not something which should be considerated as slow. The only thing left is the memory allocation but not really and in dev build, it happens even less often. Also you can always pre-allocate memory ; so at the end I don't think we can still say such statement. Of course this will be always slower than native arrays.

Quote:
I can't explain all
Why? All are properly documented.

Quote:
I would advise you to don't use the reserved param
Quote:
The reserved param should create some blank entries that are not usable, until you use ArraySet on them.
Well, it's still can be used, nothing wrong with it, but yes, doesn't follow completely documentation.
Current pre-allocates memory but don't update count. This means you still have to use Push (and not Set).
To have like documentation says, you need to use ArrayResize(), this will update the count (so real blank entry) and you will be able to use Set directly.

Quote:
A dynamic array must be destroyed in plugin_end with ArrayDestroy( &Array:which ) native, to free up memory.
I think this should be rephrased, like you should always destroy an Array/Trie right after you don't need it. Of course if you an Array/Trie globally, one of place could be plugin_end().

Quote:
for( new i; i < ArraySize( g_aArray ); i++ )
Even if just an example, it would be welcomed to cache ArraySize() value. Let's keep good practice.

Quote:
You can store a trie into an array or an array into a trie, it's fine if you do it when it should and correctly
Just to comment that this is kind of silly to say that because well what you can store anything and an Array/Trie handle is just an integer number. There is nothing special.

Quote:
you need to loop through all items and check if it contains what you need
This is no totally true with dev build, you have now ArrayFindString and ArrayFindValue.

Quote:
A trie is better for storing string than a dyn array
You should not say such shortcut. It's depending what you want to do.

Quote:
If you want a combinations between an array and a trie, you can use celltravtrie, it will allow you to traverse a trie
With dev build, you have something called Snapshot which allows you to traverse a trie, but this might be removed at some point to a different API ; but just saying there should be anyway something to traverse a trie.

About the presentation itself, it would be cool you make anchors on your natives menu so we can jump directly to the native we want.
__________________

Last edited by Arkshine; 10-09-2014 at 16:33.
Arkshine is offline