help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fortran_vec() vs data() - very first element is lost


From: Mike Miller
Subject: Re: fortran_vec() vs data() - very first element is lost
Date: Mon, 24 Oct 2016 15:27:57 -0700
User-agent: NeoMutt/20161014 (1.7.1)

On Tue, Oct 25, 2016 at 00:02:15 +0200, Patrick Boettcher wrote:
> On Mon, 24 Oct 2016 08:59:30 -0700
> Mike Miller <address@hidden> wrote:
> 
> >   auto matrix = args(0).complex_matrix_value ();
> >   auto fdata = matrix.fortran_vec ();
> >   auto data = matrix.data ();
> 
> If this works (and it does), I have a possible explanation:
> 
> What does args(0).complex_matrix_value().data() does?
> 
> It creates a temporary matrix, args(0).complex_matrix_value(), of which
> I request a pointer to its internal data-structure.
> 
> Just when I stored the pointer in my fdata-variable the matrix is no
> longer needed and it destructed. 
[…]

Yes, this is what jwe just suggested to me on irc as a possible
explanation.

I'm a little surprised that there is a temporary copy of the array being
made here, but that's a separate issue that I will learn more about when
I have some time.

I do see different addresses for fdata and data (with your original
example), so let's assume every time complex_matrix_value is called, a
new copy of the array is returned. Then the problem is exactly as you
describe, and you will need to hold on to the intermediate copy until
you are done accessing the data.

Thanks for the interesting question.

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]