I am developing some code that uses a two dimensional array as well as an array of structs. It was no problem to set it up in static memory of the system's choosing. Now I must move them to a specific physical address to use non-volatile ram. Is there a set of standard idioms for accessing muli-dimentioned arrays and arrays of structs tied to a hard address? Perhaps it is similar to accessing structures in malloc'ed memory.
Don't take my word for it, just read your compiler's manual (it's been a while since I've used C at that level, so my memory may be not quite right). This should also specify things like alignment and so on; e.g. if your array uses short values of 16 bits but the machine size is 32 bits then you need to consider whether array elements will be aligned on 32 bit boundaries or whether they will be packed.
If it's not C, then the answer will be different. For example I believe that FORTRAN does this the other way round, and you would use the standard representation mechanisms in Ada if you were using that.
You would access them (at least if the memory is ordinarily addressable) the same way, regardless if the base address was chosen by the compiler or assigned by you.
There are two ways to approach the problem of getting the proper value into the base pointer. One way is to use compiler- specific directives to tell it the address of the array when you declare the array. This may also involve using linker memory map files. The other way is to take a literal value of where you know it will be, and typecast that into a pointer.
The latter method is indeed quite a bit like using malloc, in fact you could even write your own malloc-like function that returns your pre-chosen address as a pointer type. This could be useful to do, because if you want to be able to build the same code on a PC-type platform for testing, you can have it call malloc instead to get a block of generic memory.
There is no universal way. The implementation of the multi dimensional arrays depends on the compiler. For that matter, Stroustrup recommends not using multidimensional arrays or making your own arrays by hand.
Vladimir Vassilevsky DSP and Mixed Signal Design Consultant