forum.alglib.net
http://forum.alglib.net/

Can a real_1d_array point do some double array?
http://forum.alglib.net/viewtopic.php?f=2&t=3769
Page 1 of 1

Author:  mm148881 [ Tue Aug 30, 2016 8:24 am ]
Post subject:  Can a real_1d_array point do some double array?

Hi,
I have a large array of contiguous memory in double, which I don't want to copy to a real_1d_array to save memory. Also moving (std::move) it is not an option as I want to keep the original array for further processing. Is it possible to create a real_1D_array with the original array pointer to double?

I did some fiddling with the code and modified setcontent to have p_vec to point to pContent ( p_vec->ptr.p_double = const_cast<double *> (pContent);), which seems to work. But this is really a hack and I am not convinced it does not have side effects in other parts of the library.

Thank you in advance for any help!
Max

Author:  Sergey.Bochkanov [ Thu Sep 01, 2016 4:54 pm ]
Post subject:  Re: Can a real_1d_array point do some double array?

Hello!

You can use ae_vector_attach_to_x() function, which allows to attach ae_vector object to the memory managed by x_vector object. Here "attach" means that ae_vector does not allocate its own storage, but uses one pointed by X-structure.

Initialization of the X-structure is pretty straightforward and documented in comments near its declaration. Just one notice: set owner field to OWN_CALLER, it will tell ALGLIB that this memory is owned by you.

Author:  mm148881 [ Tue Sep 06, 2016 5:18 pm ]
Post subject:  Re: Can a real_1d_array point do some double array?

Hi Sergey,
Thank you very much for your help.
Max

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/