Re: rtlmovememory and vectors
"Super Giraffe" <muzmail@gmail.com> wrote in message
news:1149093262.520320.178970@c74g2000cwc.googlegroups.com...
Hi everybody,
I'm writing a program where I need to copy data from a huge pointer
array to a vector.
I haven't figured out how to do this but I am aware that RtlMoveMemory
can be used to copy data from pointer arrays to structs like so:
RtlMoveMemory(&bih, pDIB, sizeof(BITMAPINFOHEADER));
where bih is a struct, pDib is a pointer array, and the third parameter
is the number of elements to be copied. So I was thinking I could do
the following:
RtlMoveMemory(&m_3DVector, &(frame->pBuffer), elements);
where m_3DVector is a vector and pBuffer is a pointer array. Too bad it
isn't working, can somebody help me and tell me if I can use vectors
like this or what I'm doing wrong?
It's not working because you're clobbering the vector with the contents of
the frame buffer. A vector stores it's elements in a separately allocated
buffer, not inline in the object (if it didn't use a separate allocation, it
wouldn't be able to change the allocation size).
You could use RtlMoveMemory though:
RtlMoveMemory(&m_3DVector.front(), &(frame->pBuffer), elements);
You solution using std::copy is more portable, although using RtlMoveMemory
(or better yet, memcpy) might give better performance - only profiling will
tell.
-cd