0

I want to assign a fix memory address to a two dimensional array. Say for example for simple integer we do like this: int *p = (int *)0xabcdf34;

I need to allocate memory starting from fix location say 0xf3ab25 to a two dimensional array. How can I do it. Please help.

EDIT: I am playing with memories. I want to allocate all the memory of a matrix to cache or main memory. I want to check what is the effect on computations and run time. I am using simulator, so i have direct address. Say I want to use matrix of matrix[100][100]

2
  • Why? What problem does this solve? Sounds like you are asking us to solve the last 10% of your problem that makes no sense.. I could be wrong, but some context would be nice because this is wrong in almost all circumstances. Commented Oct 5, 2012 at 22:56
  • Maybe not fixed addresses, but I've certainly run into this where the address is provided by malloc. Commented Oct 5, 2012 at 23:10

2 Answers 2

6

Something like this:

int foo() {
  int (*p)[10] = (int (*)[10])0xf3ab25;
  return p[3][4];
}
Sign up to request clarification or add additional context in comments.

5 Comments

And that's going to work in the general case? I think taking the question at face value may be a bad idea on this one.
Thinking about it... I'm removing the downvote until we get more info from the OP. Hard to knock you for answering the question.
I'm not his mom, I'm just answering the question. And yes, p is a 2-dimensional array. This code compiles fine and produces the correct address arithmetic (the read of [3][4] is at an offset of 136 bytes from the initialization address).
I think you saw my comment before I changed it. Yes, I agree with you, which is why I removed the downvote (though I have a hunch the OP is misguided). And yes, the declaration is correct, that was a mental blip on my part.
I am playing with memories. I want to allocate all the memory of a matrix to cache/main memory. And want to check what is the response on computations. I am using simulator, so i have direct address. I hope now my question is clear.
0

You cannot decide the address of the memory to be allocated, as you cannot decide the real layout of your program.

It is decided by the compiler (static variables) or at runtime (automatic variables and dynamically allocated memory)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.