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

Passing around an array initialized with attach_to_ptr
http://forum.alglib.net/viewtopic.php?f=2&t=4605
Page 1 of 1

Author:  mfabjancic [ Tue May 21, 2024 1:33 pm ]
Post subject:  Passing around an array initialized with attach_to_ptr

Hi!

For example, consider the following code snippet

Code:
minnlcstate state;

{
    std::vector<double> dataForC = ...;

    real_2d_array C;
    C.attach_to_ptr(dataForC, nRows, nCols);

    real_1d_aray CT = ...;

    minnlcsetlc(state, C, CT);
}

// At this point `dataForC` is no longer valid, and with it the pointer to which `C` was attached.
// Is it safe to delete data to which `C` was attached? I.e., does ALGLIB make a copy of object `C` that was passed to `minnlcsetlc`?
minnlcoptimize(state, ...);


Please answer the questions above minnlcoptimize in the code snippet.

Author:  Sergey.Bochkanov [ Tue May 21, 2024 5:29 pm ]
Post subject:  Re: Passing around an array initialized with attach_to_ptr

Hi!

Yes, all ALGLIB functions copy data from and to parameters, but do not persistently store references to these parameters. After setlc() is done, you can do whatever you want with variables C and CT, there will be no dangling pointers.

Sergey

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