lundi 17 juin 2019

C++ Three dimensional array random access performance

I would like to boost the performance of application which stores 3D map. Currently, it uses QtreeNode as a structure for storing the map. However, accessing random position with coordinates x,y,z has a complexity of log2n.

I would like to store part of the map which I know is accessed 90% of the time in the static array defined as:

Tile* tileArray[16][3500][3500] // [z, x, y];

The reason I set z as first dimension is that application iterations are usually done floor by floor and row by row.

Tile* is a pointer to a data structure containing information about that position on 3D map. Since the system is 64bit and the pointer size is 8byte and it takes a total of 1.5GB of RAM.

I would like to ask if there is some problem with random accessing such an array with x,y,z coordinates. Logically, the complexity should be O(1) but I am not sure about how CPU calculates the exact position in the memory.

I am not afraid of excessive RAM usage.




Aucun commentaire:

Enregistrer un commentaire