Page 3 of 3
Re: map editor help
Posted: Thu Feb 25, 2010 6:37 pm
by eatcomics
Moosader wrote:XianForce wrote:acerookie1 wrote:thanx moosader!
. you should really add this to your 2d map editor book.
For sure... You may want to also consider adding deallocation of a dynamic 3D array... haha
Oy vey. I did, at one time, have a dynamic 3D array working. But MusuGo uses a 1D array lol. :p (it might use three/four separate 1D arrays, even. Laziness...)
that's more efficient than using multidimensional arrays they can take up a lot of memory (although you'd probably be alright to use them)
Re: map editor help
Posted: Mon Mar 08, 2010 11:48 am
by Falco Girgis
eatcomics wrote:Moosader wrote:XianForce wrote:acerookie1 wrote:thanx moosader!
. you should really add this to your 2d map editor book.
For sure... You may want to also consider adding deallocation of a dynamic 3D array... haha
Oy vey. I did, at one time, have a dynamic 3D array working. But MusuGo uses a 1D array lol. :p (it might use three/four separate 1D arrays, even. Laziness...)
that's more efficient than using multidimensional arrays they can take up a lot of memory (although you'd probably be alright to use them)
Actually, it's not. It's stored sequentially in memory, so the only difference between using a giant 1D and 2D arrays is how you are accessing them.
When you do array[3][2], the compiler is moving the pointer "array" (which points to the first object) to the correct location by adding an offset.
array + 3*COL_SIZE*sizeof(object) + 2*sizeof(object)
(the sizeof() is implicit in C/++).
The only difference between that and a one-dimensional array is an extra offset being applied. And I'm guessing that if Rachel really is using a 1D array, she's just applying that offset manually, which means that the chances are the compiler would optimize a 2D array better than a programmer emulating 2D array access.
Re: map editor help
Posted: Mon Mar 08, 2010 12:43 pm
by K-Bal
There are also some low level tricks to avoid demand paging and optimize cache usage when using arrays and those seem more intuitive with 1D arrays. But multi-dimensional arrays are internally 1D arrays like Falco said, so if you are aware of the memory layouts of your data it doesn't make a difference. This is also only important for arrays > 4kb.
Re: map editor help
Posted: Mon Mar 08, 2010 7:31 pm
by eatcomics
GyroVorbis wrote:eatcomics wrote:Moosader wrote:XianForce wrote:acerookie1 wrote:thanx moosader!
. you should really add this to your 2d map editor book.
For sure... You may want to also consider adding deallocation of a dynamic 3D array... haha
Oy vey. I did, at one time, have a dynamic 3D array working. But MusuGo uses a 1D array lol. :p (it might use three/four separate 1D arrays, even. Laziness...)
that's more efficient than using multidimensional arrays they can take up a lot of memory (although you'd probably be alright to use them)
Actually, it's not. It's stored sequentially in memory, so the only difference between using a giant 1D and 2D arrays is how you are accessing them.
When you do array[3][2], the compiler is moving the pointer "array" (which points to the first object) to the correct location by adding an offset.
array + 3*COL_SIZE*sizeof(object) + 2*sizeof(object)
(the sizeof() is implicit in C/++).
The only difference between that and a one-dimensional array is an extra offset being applied. And I'm guessing that if Rachel really is using a 1D array, she's just applying that offset manually, which means that the chances are the compiler would optimize a 2D array better than a programmer emulating 2D array access.
Damn you, my book lied to me, its old I guess it should be expected