Click here to Skip to main content
15,894,907 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to map a matrix index to a memory location Pin
Leif Simon Goodwin29-Mar-18 1:26
Leif Simon Goodwin29-Mar-18 1:26 
We have a device that returns data from a 2D grid thus each data value is indexed by its row and column. The number of rows and columns is not fixed, as the device can be reconfigured, but in normal use the number of rows and columns does not change. We store the data values in memory for subsequent retrieval.

Our problem is how to convert a row + column pair {x,y} into an address in the memory. This sounds trivial:

offset = x * (total_number_of_columns) + y;

However, we have to do this very very quickly, and using as little processor power as possible. A multiplication is not good. We do not need to store the values contiguously as row, row, row etc. We do have limited memory so cannot be too wasteful.

One way is to store the data values in a grid whose number of columns is always a power of 2. Thus if our device generates 20 rows and 50 columns of data, we store them in a 20 rows by 64 columns grid. This means the data is not packed tightly in memory. To convert {x,y} into a memory location:

offset = x << 6 + y;

The quickest way I can think of is to use a look up table:

offset = lookup[x] + y;

Thus lookup is the offset to the start of each row in memory.

So, my question is how can we do this as fast and simply as possible? Is there a quicker way?
AnswerRe: How to map a matrix index to a memory location Pin
Jochen Arndt29-Mar-18 2:39
professionalJochen Arndt29-Mar-18 2:39 
GeneralRe: How to map a matrix index to a memory location Pin
Leif Simon Goodwin29-Mar-18 3:12
Leif Simon Goodwin29-Mar-18 3:12 
GeneralRe: How to map a matrix index to a memory location Pin
harold aptroot29-Mar-18 3:44
harold aptroot29-Mar-18 3:44 
AnswerRe: How to map a matrix index to a memory location Pin
Daniel Pfeffer29-Mar-18 5:06
professionalDaniel Pfeffer29-Mar-18 5:06 
QuestionWhat is the best tool to find C++ Memory issues Pin
ptr_Electron29-Mar-18 1:06
ptr_Electron29-Mar-18 1:06 
AnswerRe: What is the best tool to find C++ Memory issues Pin
Leif Simon Goodwin29-Mar-18 1:28
Leif Simon Goodwin29-Mar-18 1:28 
GeneralRe: What is the best tool to find C++ Memory issues Pin
ptr_Electron30-Mar-18 10:12
ptr_Electron30-Mar-18 10:12 
QuestionMemory allocated out side of try and Delete in finally Pin
ptr_Electron28-Mar-18 23:46
ptr_Electron28-Mar-18 23:46 
AnswerRe: Memory allocated out side of try and Delete in finally Pin
Jochen Arndt29-Mar-18 0:17
professionalJochen Arndt29-Mar-18 0:17 
GeneralRe: Memory allocated out side of try and Delete in finally Pin
ptr_Electron29-Mar-18 1:05
ptr_Electron29-Mar-18 1:05 
GeneralRe: Memory allocated out side of try and Delete in finally Pin
Jochen Arndt29-Mar-18 1:44
professionalJochen Arndt29-Mar-18 1:44 
Questionerror C2143: syntax error: missing ':' before 'constant' Pin
ForNow27-Mar-18 15:53
ForNow27-Mar-18 15:53 
QuestionRe: error C2143: syntax error: missing ':' before 'constant' Pin
David Crow27-Mar-18 16:47
David Crow27-Mar-18 16:47 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
ForNow27-Mar-18 16:52
ForNow27-Mar-18 16:52 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
Peter_in_278027-Mar-18 18:13
professionalPeter_in_278027-Mar-18 18:13 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
ForNow28-Mar-18 14:50
ForNow28-Mar-18 14:50 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
Victor Nijegorodov27-Mar-18 21:18
Victor Nijegorodov27-Mar-18 21:18 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' Pin
ForNow28-Mar-18 0:31
ForNow28-Mar-18 0:31 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
Richard MacCutchan27-Mar-18 22:08
mveRichard MacCutchan27-Mar-18 22:08 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
Jochen Arndt27-Mar-18 22:41
professionalJochen Arndt27-Mar-18 22:41 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' The Hercules makefile has V1,V2,V3,V4 Pin
ForNow28-Mar-18 15:44
ForNow28-Mar-18 15:44 
Questionproblem understanding a functionality of constructor. Pin
Tarun Jha27-Mar-18 4:39
Tarun Jha27-Mar-18 4:39 
AnswerRe: problem understanding a functionality of constructor. Pin
Jochen Arndt27-Mar-18 4:55
professionalJochen Arndt27-Mar-18 4:55 
AnswerRe: problem understanding a functionality of constructor. Pin
Richard MacCutchan27-Mar-18 5:18
mveRichard MacCutchan27-Mar-18 5:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.