Raw data copy into Array

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Raw data copy into Array

Jan Paral-2
Hello

i'm doing on isdat(physical data server) API for octave and i have big
problem.
When i get array of data ( double d[] ) i need to copy then into Array
by mempcy(). I don't want to copy them value by value.

Is it possible?


Reply | Threaded
Open this post in threaded view
|

Re: Raw data copy into Array

Paul Kienzle
Jan Paral wrote:

> Hello
>
> i'm doing on isdat(physical data server) API for octave and i have big
> problem.
> When i get array of data ( double d[] ) i need to copy then into Array
> by mempcy(). I don't want to copy them value by value.
>
> Is it possible?

Yes.  Preallocate your array using,
     Matrix x(m,n);
 You can then populate it directly using
     double *xp = x.fortran_vec();
     memcpy(xp,d,sizeof(*xp)*m*n);

You can usually eliminate the copy
altogether by passing xp to whatever
fills it (e.g., read), but you can't do it
if the library you are using returns you
an array that it allocates.

Paul Kienzle
[hidden email]