THE GOAL
I'm building a world generator that should be able to dynamically add "voxels" to some sort of list as the camera nears the edge of what already exists. Each voxel should be as efficiently accessible as possible since a few hundred voxels from a list of thousands will need to be accessed every frame.
APPROACHES I'VE CONSIDERED
1) My first thought was a multidimensional array of voxels, it's indices being the x and y coordinates of the voxel:
Voxels[,] voxels = new Voxel[128,128];
Pros: This should be very fast to pull from assuming I know the coordinates of my voxel: Voxel myVoxel = voxels[x, y];
Cons: I either have to cap the world size, or I have to completely recreate the array every time I want to generate new terrain...
2) To fix this I figured I could just store the x & y values in a string, and use them as keys in a dictionary. Dictionary<string, Voxel> voxels = new Dictionary<string, Voxel>();
Voxel myVoxel = voxels[x + "," + y];
Then adding to the list would be as simple as calling a .Add(); method.
QUESTIONS
1) How does the efficiency of pulling from an array differ from a dictionary. In my head, an array would be multitudes faster since I assume Dictionaries must iterate through every key to check equality (excuse my ignorance if I'm wrong)
2) If an array truly is that much faster to pull from, would destroying and recreating an array of upwards of hundreds of thousands of items multiple times a second (dependent on chunk size) be worth it?
Mind you the target platform is mobile phones, and not every voxel generated will be stored in ram, so the list will never become dangerously large. Testing still needs to be done to determine specific sizes, but the concept is there...
Thanks in advance