I need to treat a 1D-RAM buffer as a 2D array of a different type than what was declared, and have questions on different methods and what provides best performance.
Questions:
1. How to set things up so I can access an element by something like "ptr[x][y]"?
2. Would any particular method be faster than another?
I have a buffer that is declared for writing as
unsigned char buffer[FIELD_NUM][FIELD_SIZE];
Where each field is a 240x720 array (FIELD_SIZE=240*720). For reading from the buffer, a field is treated as a 240x360 array of unsigned short.
I can think of one way to "map" the buffer as an array of unsigned short:
One is to something like
unsigned short* ptr = &buffer[0][0];
for (i=0; i < 240; i++)
for (j=0; j < 360; j++)
ptr[j + i*360]
Would it be better to set up indexing so I could do something like
ptr = &buffer[0][0], so that I could access the 2D array by ptr[j]?
How do I set up ptr? (So, far no luck with what I *think* should work)
Appreciate any feedback!!