I have acquired a memory location from DirectX where my vertex information is stored. An extremely convenient way to deal with vertex information is to use a std::vector<> of a struct containing vertex info.
Given that I have a pointer to a large buffer, could I use a std::vector to manage the elements in the buffer? Constructing a std::vector regularly causes it to have its own address, which isn't really what I want. Could I use operator placement new somehow?
The elements of
std::vector
are allocated dynamically on the heap (withnew
bystd::vector
itself) in such a way that they are always contiguous in memory. So if your structure isvertex
, usingstd::vector<vertex>
is not what you want as the elements of the vector will not be located in your large buffer.You could use
std::vector<vertex*>
however, like for example:Yes you can. Use custom allocator. In this allocator return address of your DirectX memory.
Here is a complete examlpe based on an answer from Compelling examples of custom C++ STL allocators?. This solution uses placement new in the allocator.