You are not logged in.
Is it possible to make a 2D array (or whatever-dimension) array like this...
collumn 1 collumn 2
Emulated Address Real Memory address*
(int) (int *)
+----------------------+----------------------------+
| 0 | 0xA0 | <-- row 1
| 1 | 0xA1 | <-- row 2
| 2 | 0xA2 | <-- row 3
+----------------------+----------------------------+
* A = Address.
is it possible to make an array like that?
if it is, please tell me how to do it...
thanks.
... I'm trying to make an emulator to emulate the simplest memory.
milo64.
Registered Linux User: #555436
My Blog @ http://milo64.blogspot.com/
Offline
Given your other posts, I'm assuming you mean in C, right?
If so, the answer is yes, but specifically how will depend on a needed clarification of your question. What you present doesn't really need to be a 2 dimensional array, just one: that looks like a simple list of memory addresses, right?
At the simplest you can declare an array with two dimensions `iny myarray[2][3];` but to make the table you put up there you'd only need `int *myarray[3];`
If you also wanted space allocated somewhere that each element of that list pointed to, you could allocate them separately:
int *myarray[3];
myarray[0] = (int *) malloc(sizeof(int));
myarray[1] = (int *) malloc(sizeof(int));
myarray[2] = (int *) malloc(sizeof(int));
Obviously with many entries this should be in a loop. Perhaps not as obviously, why would you not just malloc a larger block of memory to start with?
What is the end goal?
EDIT: actually, upon rereading your question, the mallocs are probably irrelevant. `int *myarray[3]` will get you the array you are looking for. Just realize that until you point those pointers to memory you 'own' you shouldn't assign to or read from them.
Last edited by Trilby (2013-04-19 10:06:31)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
If you're trying to imitate memory, I'd probably just use an array of unsigned char. That's essentially what memory is anyway. Use "regular" unsigned instead if you want to speed up int-sized operations at the expense of char-sized ones (but you'll have to scale the "addresses" by sizeof(int) if you still want to address individual chars within the array).
I hereby vow to stop posting before breakfast.
Last edited by Trent (2013-04-19 13:50:19)
Offline
okay, SOLVED thank you...
milo64.
Registered Linux User: #555436
My Blog @ http://milo64.blogspot.com/
Offline