3 Dimensional array using ArrayCreate()?
Greetings,
I have been using the "normal" method of creating arrays for example: Code:
new some_array[33],lately I started using ArrayCreate, which works great on my end, but I'm lost in ideas using it in 3D arrays, for example: new some_array[32][64][128]; the only idea i think of is creating a normal array then using it inside an "Array:" example: Code:
new some_array[64][128]; |
Re: 3 Dimensional array using ArrayCreate()?
A dynamic array does not support multiple dimensions. It would probably be better to understand why you think you need a 3D array. Many of the types of questions like this end up simply needing to think about the use case differently. So, what type of data are you trying to store?
|
Re: 3 Dimensional array using ArrayCreate()?
Quote:
If you know the maximum number of elements then you use a normal array. If you do not(the number of elements can grow over time with no known upper bound) you use a dynamic array as it can grow in size. This is the only criterion to choose between a normal and a dynamic array. Performance is not a concern. Dynamic arrays are usually implemented as "normal" arrays, but allocated dynamically on the heap(as opposed to the stack which is used for regular arrays). When the dynamic arrays runs out of space it is simply reallocated with a bigger size. For example, it is as if you did the following(pseudocode): PHP Code:
https://i.imgur.com/tGzuD5W.png (there is a smarter way to do this, by liniarising all dimensions into a single array and manually doing the math to compute the real index) |
Re: 3 Dimensional array using ArrayCreate()?
Quote:
Code:
new SETTING_NAME[MAX_SETTINGS][64],SETTING_PLUGIN[MAX_SETTINGS][64],Code:
new SETTING_NAME[MAX_SETTINGS][64],SETTING_PLUGIN[MAX_SETTINGS][64],Code:
SETTING_VALUE_GET[MAX_SETTINGS][MAX_VALUE_NAMES][32],Quote:
"brings fast, easy, and efficient dynamic storage into PAWN coding" and I recall reading it somewhere in some post, and for looping I know it will do the same effect. tho to search for something you have to loop unlike ArrayFind, maybe it's a lot better? or does it have the same effect? the idea and information you've posted is what I needed, thank you very much! |
Re: 3 Dimensional array using ArrayCreate()?
"Bring fast and efficient DYNAMIC storage". As I said before, dynamic means the array is dynamically allocated on the heap and can be resized if full, to make space for more elements. Normal arrays can not be resized, this is the only difference.
The statement you quoted does not say or imply dynamic arrays are somehow magically faster than normal arrays. ArrayFind uses a loop to find the element. |
| All times are GMT -4. The time now is 11:32. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.