forum.alglib.net

ALGLIB forum
It is currently Tue Oct 15, 2024 3:31 am

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: 6
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 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 925
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: No registered users and 1 guest


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