I’m looking to implement a data structure in C++ that allows me to access rows and columns in a contiguous manner. In other words, I want to ensure that when I sequentially access rows, say row [0], row [1], row [2], they are stored contiguously in memory, and similarly, when I sequentially access columns, say column [0], column [1], column [2], they are also stored contiguously.
I’ve tried using a two-dimensional array T[][]
, but it doesn’t guarantee contiguous storage for both rows and columns. I’ve also considered using a one-dimensional array and manually converting indices, but this approach could introduce complexity and potentially affect performance.
Thank you!
I’m curious to know if there are better techniques or data structures available to achieve this goal. If so, how should I implement them?
yourong shengbai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.