-1

I have a C++ class which is something like

class Block {

...

scoped_array<Columns> columns_

...
}

Now as i understand because of using an array, the memory for Columns array will be contiguous .

Several parts of the code access the elements of this array randomly i.e. columns_[x].

I want to re-factor the code so that contiguous memory is no longer a constraint. Therefore i assume i have to replace the scoped_array with something which is not contagious.

However if i can i don't want to re-factor other code so that the columns_[x] type access is still possible.

Is there a data structure available that i can use here? I suppose i can replace it with C++ list but then i will lose the columns_[x] style access. is there any data-structure in boost i can use instead which doesn't require contiguous memory?

4
  • 1
    How about std::deque? Commented Jun 6, 2013 at 15:17
  • 1
    Do you mean contiguous instead of contagious?
    – Adri C.S.
    Commented Jun 6, 2013 at 15:18
  • Yes contiguous, sorry , i fixed it Commented Jun 6, 2013 at 15:20
  • @JoachimPileborg Thanks, i am new to C++. in order to be equivalent to scoped_array, i supposed i will have to use shared_ptr<deque> right? Commented Jun 6, 2013 at 15:54

1 Answer 1

0

std::deque provides almost the same methods as a vector but does not have a restriction of keeping data contiguous in memory.

(based on an earlier comment suggesting deque)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.