Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

convert std vector to and from CniVector

I am using the class CNiReal64Vector and need an optimized way to copy the contents of a std vector into a CniVector, and vice versa.

I am using a non-Ni library in my application and can't use Ni types throughout. Can someone point me in the right direction?

 

 

 

 

0 Kudos
Message 1 of 4
(6,758 Views)
You can use memcpy().

Mark E.
National Instruments

0 Kudos
Message 2 of 4
(6,702 Views)

Just to add a little more information to Mark's post, the following line of code is all that is necessary to copy elements of one vector to another:

 

 

double data[4] = {2.345, 4.567, 2.95666, 8.9222};
CNiReal64Vector cniVect(4, data);
vector stdVect(4);

memcpy(&stdVect[0], &cniVect[0], sizeof(double) * 4);

 

This is because the elements of both vectors are all stored contiguously in memory, and dereferencing the first item in the collection gets you the address of the first element.

 

NickB

National Instruments 

 

0 Kudos
Message 3 of 4
(6,687 Views)
Thanks
0 Kudos
Message 4 of 4
(6,681 Views)