Array VS Multiple Array
Hello there!
I was thinking about why ZP50's dev team using multiple arrays to store zombie class data (name, desc, HP etc.) Wouldn't be a better to store them only in one with nested arrays? I think they did this for reason but I don't know. If I am right and I use the array in array method which one is better to retreive data with netives? 1. Using multiple natives for retreive name and desc. OR 2. Using only one native that retreive the complett object. For example a zombie class's name and desc. Ofc I don't want to modify their code. I only want to implement mine as bast I can. Thanks for your advices. |
Re: Array VS Multiple Array
I think there is ArrayPushArray and ArrayGetArray act like nested arrays for AMXX. (I have never messing around with it though)
Something like this PHP Code:
But hey, I haven't use it before so I might being bs here |
Re: Array VS Multiple Array
When I said nested arrays I meant exactly your example. Sorry for misunderstanding. Anyways this is totaly fine. Currently I'm using this with the 2nd point. So every time when I need the name as well as the description I have to call natives twice like:
static name[32]; get_my_item_name(item_id, name, charsmax(name)); static desc[32]; get_my_item_desc(item_id, desc, charsmax(desc)); BUT this one seems mutch better. static name[32], desc[32]; get_my_item(item_id, name, charsmax(name), desc, charsmax(desc)); Even if I don't need them bot I can use something like this. Right? static desc[32]; get_my_item(item_id, _, _, desc, charsmax(desc)); In this case what do you think? Is it better than their implementation? |
Re: Array VS Multiple Array
The second one
Since its 1 native call. |
Re: Array VS Multiple Array
All right. Thanks! And what do you think? Why did they use the first one?
|
Re: Array VS Multiple Array
You could also do something similar to engine entity_get_* and fakemeta pev, it does not really matter, choose what you are comfortable with.
Code:
As for the first question, I do also use the same method as celena. Honestly it does not matter either. |
Re: Array VS Multiple Array
I think that they think it would be easier than creating array in array + wouldn't it be the same thing even if you creat them manually or add them to a existent array?
|
Re: Array VS Multiple Array
I agree that it doesn't matter. However, I want to point out a situation in which it having the data together vs splitting the data would matter.
If dynamic arrays were implemented under the hood using a structure like linked lists then it would make a difference. Accessing an index into an array, like array[i] is always an O(1) operation, meaning it doesn't matter if you access the first or the last index, it takes the same number of steps(or if it helps you better visualize this, "the same time", even if not technically correct). In a linked list, to access the i-th index you have to loop thru all the other i-1 elements to get to the i-th element. This means that accessing the first element is only one step and accessing the last element takes a number of steps equal to the length of the list. Let's say we split the data in 3 parts: With arrays, we would have something like: Code:
array1[i] <- one stepWith a list, assuming we have a long list and assuming we want to access the element with the index = 1 million Code:
list1[1000000] <- 1000000 stepsSome of you may be quick to point out that asymptotically O(3*n) = O(n) and you'd be right, but for a large "n" the constant 3 actually matters and can cause a very noticeable slowdown. For small "n" it wouldn't make a difference. You can code just fine without understanding the above explanation, especially because you don't work with huge amounts of data in plugins and we don't have list like structures, but I figured someone could find this useful. |
Re: Array VS Multiple Array
Posts by both of you are very interesting. Always good to learn new things. :3 Thank you!
|
| All times are GMT -4. The time now is 02:31. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.