arrays - C# Efficiently store large int data -


evening all, i'm in predicament can't decide/know of best method storing "simple" large amounts of int datatypes.

now @ moment using flattened array int[] thedata = new int[size * size];, because storing 1 layer i'm needing @ least 3 layers. initial through process either use a:

dictionary<uint, int[]> thenewdata = new dictionary<uint, int[]>(); (the key layer)

but i've not had experience dictionaries believe cause problems accessing data via array index in flat array thedata[x + y * width] = ...

or simply:

int[,] thenewdata = new int[layercount, size * size];

the above 1 makes me feel dirty.

i triple original flat array size , apply offset next layer...

anyway i've got take account ridiculously large maps, width x hight 1,000 x 1,000 (tiles) that's 1,000,000 tiles stored int's somewhere (i think...). data access needs fast i've go deal updating potentially entire "active" layer.

if please "explain" why suggested method best suited appreciated, thank you.

if you're storing multiple nxn grids, what's wrong int[,,] foo = new int[layercount, size, size];? it's easy index , plenty fast if you're doing random access. if you're doing sequential access, can better performance jagged arrays, initializing them bit inconvenient.

the other problem multidimensional arrays (i.e. int[,,]) require single contiguous block of memory. if have 3 layers of 1000 x 1000, that's not problem. because you're talking 12 megabytes. if size 1,000,000 rather 1,000, you'd allocating 12 gigabytes, give trouble.

a jagged array, way, of form int[][][] foo = new int[layercount][][]; have initialize other dimensions individually. it's not difficult, messy. around needing single contiguous block of memory, @ cost of runtime performance if you're accessing randomly.

or, use hybrid: int[,][], can think of array of two-dimensional arrays. in case, each layer single allocation.

whatever case, if know size of layers , know how many have, there's no reason use array.

you of course make single one-dimensional array line int[] messy = new int[layercount * size * size], , own indexing. seems lot of unnecessary work, though.

for information performance characteristics of arrays in c#, see http://blog.mischel.com/2013/05/08/are-jagged-arrays-faster-than-rectangular-arrays/. haven't done performance comparisons 3 dimensional arrays, expect them similar.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -