3

For my embedded systems application, I want to allocate memory from a particular address. I know it can be dangerous but I just want to do it for testing purpose. So If I could point array globally to a particular memory address I can actually allocate array size of memory. I can point integer to a specific memory address like:

int *fsp_new_addr = (int*) 0xFF000000;

how can I do same thing for array, or is there any alternative way to do this task ?

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • are you looking for [placement new](https://en.cppreference.com/w/cpp/language/new) ? – 463035818_is_not_an_ai Jan 21 '19 at 11:09
  • Note that this approach does not actually *reserve* any memory. You should take precautions that linker doesn't place something else to that memory location. – user694733 Jan 21 '19 at 11:20
  • Actually the pointer has no idea what is pointing to (if it is an array, a matrix...) But if you do know that it is an array, why don't you use the array instead of another pointer? – Jose Jan 21 '19 at 11:20

1 Answers1

5

It's exactly the same. fsp_new_addr[1] is the first element after that address.

Of course, as you stated, this can be dangerous, as you are not programmatically allocating memory, but deciding that this bit of memory is going to be a dedicated array for some purpose.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62