forum.alglib.net

ALGLIB forum
It is currently Mon Jul 15, 2024 2:15 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Passing around an array initialized with attach_to_ptr
PostPosted: Tue May 21, 2024 1:33 pm 
Offline

Joined: Tue Apr 30, 2024 11:08 am
Posts: 3
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.


Top
 Profile  
 
 Post subject: Re: Passing around an array initialized with attach_to_ptr
PostPosted: Tue May 21, 2024 5:29 pm 
Online
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 921
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Sergey.Bochkanov and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group