View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-06-2017 , 14:00   Re: [ TUT ]Dynamic Array
Reply With Quote #42

Quote:
why cellsize is equal to 1? Since the Array that we have created is Empty at the begining shouldn't be Size equal to 0?
It's not the size of the array. Dynamic arrays have no fixed size, that's why they exists, to let you store unlimited data. The cellsize param is the size of the data that will be stored in that array. Since I used it to store integers, cellsize is 1. If I stored strings with 128 size, then I would have used 128 there.

Quote:
Also is there a way to add a key and pair to the Array something like that?
You can pair a trie with arrays, it can do wonders.

Quote:
Of course, since we can add more than the specified size in a static array . So i don't see how it's smart ...
I'm not sure to understand what you mean. A "normal" array has a fixed size. I said it' "smart" more as a joke, but it tells you that if you don't work with unkown number of elements or elements without a known maximum, then you should always use normal arrays. For example, if you want to store kills per player, it is better to use a normal array, as you know you have only 32 players at max. If you had to read a file and save all data, it is good to use a dynamic array, as you don't know how many things are in that file.
__________________
HamletEagle is offline