For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > rtlmovememory and vectors









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author rtlmovememory and vectors
Super Giraffe

2006-05-31, 7:15 pm

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?

Thanks in advance

Super Giraffe

2006-05-31, 7:15 pm

So nobody answered my question, but I found something that works pretty
well in the standard template library. The std::copy function

std::copy(&frame->pBuffer[0],
&frame->pBuffer[frame->nbLig*frame->nbCol*3], m_3DVector.begin());

first parameter is the address of the first element of the source,
second parameter is address immediately after the last element of the
source,
and the third parameter is the address of the destination.

If anybody else wants to copy from a pointer array to a vector. Use
std::copy.


Super Giraffe wrote:
> 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?
>
> Thanks in advance


Carl Daniel [VC++ MVP]

2006-05-31, 7:15 pm


"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



Super Giraffe

2006-05-31, 7:15 pm

Thanks for the reply. Although I have moved past that problem I
appreciate the attention you gave to my question.

Carl Daniel [VC++ MVP] wrote:
> "Super Giraffe" <muzmail@gmail.com> wrote in message
> news:1149093262.520320.178970@c74g2000cwc.googlegroups.com...
>
> 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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com