View previous topic :: View next topic |
Author |
Message |
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1586
|
Posted: Mon Jul 10, 2017 12:27 am Post subject: 2D array or 3D array |
|
|
how would two dimensional array would be in assembly.
or more.
EDIT:
who can write a small program with 5x5 (5d array).
and assign random values to these boxes or whatever they called technically.
and when we click on a box the value changes randomly.
anyone interested in this?
also since i talked about dimensional arrays.
why not making a new value type with a table to set address of the value for a game that use dimensional arrays.
it would be great feature. (and it must appear as columns and rows). _________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Mon Jul 10, 2017 10:46 pm Post subject: |
|
|
int x[n][m] with index x[i][j] translates to int x[i*n + j] and of course in bytes that translates to address of x + i*sizeof(int)*n + j*sizeof(int) or x+i*4*n + j*4, something like lea eax, [eax + ebx*4 + ecx] (not sure if that's entirely valid but).
the reason is that memory is flat so if you take a grid like this
Code: |
12345
00- XXXXX
05- XXXXX
10- XXXXX
15- XXXXX
20- XXXXX
|
and just stick them end to end
00- XXXXX 05- XXXXX 10- XXXXX 15- XXXXX 20- XXXXX
to move 1 row you have to move 5 Xs in memory. To move i rows you have to move i*5 Xs in memory, and to move i rows with n elements per row you have to move i*n Xs. To then select a particular x in the row (aka column) you just have to move by individual Xs, hence the +j. The same applies to higher dimensions, x[n][m][o] for x[i][j][k] is x[i*n*m + j*m + k]. |
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1586
|
Posted: Tue Jul 11, 2017 3:23 am Post subject: |
|
|
thank you free...
good example, even tho its a lil bit complicated to me.
and I didn't get everything.
but one thing here, you said size.of(int) so addresses will be 4 bytes in memory.
then why in your example its 5bytes?
BTW I don't understand multi dimensional arrays (technically I mean)
they are different than normal array _________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Tue Jul 11, 2017 9:33 am Post subject: |
|
|
OldCheatEngineUser wrote: | but one thing here, you said size.of(int) so addresses will be 4 bytes in memory.
then why in your example its 5bytes? | The Xs weren't meant to represent bytes but elements, and the numbers 1-5, 5,10,etc. were meant to represent the 1 dimensional indices (the 2D indices are pretty easy to see/count for a small 5x5)
OldCheatEngineUser wrote: | BTW I don't understand multi dimensional arrays (technically I mean)
they are different than normal array | except that they're really not. They are, mostly, pointers to a chunk of memory numElements*sizeof(element) in size. The only difference is whether you have "syntactic sugar" to let you access it in terms of multiple-dimensions.
https://www.cse.msu.edu/~cse251/lecture11.pdf seems to provide good info on the subject |
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1586
|
Posted: Tue Jul 11, 2017 11:34 am Post subject: |
|
|
FreeER wrote: | https://www.cse.msu.edu/~cse251/lecture11.pdf seems to provide good info on the subject |
pretty much good info.
thank you.
ill try the examples of dimensional array. (and debug the example.)
also there is a good subject too, which is pointers to arrays.
this is also a good thing to learn. _________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
|