help-octave
[Top][All Lists]
Advanced

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

Re: yet another DLD question


From: Andy+Alison Adler
Subject: Re: yet another DLD question
Date: Wed, 11 Nov 1998 21:47:22 -0500

John W. Eaton wrote:
> On  4-Nov-1998, Andy+Alison Adler <address@hidden> wrote:
> | I've got this bizarre bug:
> |
> | if I put my code
> |
> | [SNIP]
> |    Octave_map As;
> | [SNIP]
> |    ColumnVector coefV=  As["coef"] . vector_value();
> |    double * coef =  coefV . fortran_vec();
> |    for ( int i= 0; i<  nnz; i++ )
> |       printf("a= %f\n", *(coef+i));
> | [SNIP]
> |
> | then it works fine, giving output
> |
> | a= 1.000000
> | a= 2.000000
> | a= 3.000000
> | etc.
> |
> |
> | However, if I try to abbreviate by putting
> |
> | [SNIP]
> |    double * coef =  As["coef"] . vector_value() . fortran_vec();
> |    for ( int i= 0; i<  nnz; i++ )
> |       printf("a= %f\n", *(coef+i));
> | [SNIP]
> |
> | then the first value printed is always wrong
> | a= 39.399666
> | a=  1.000000
> | a=  2.000000
> |
> | (the first value is often 39.??? but is sometimes different)
> |
> | MY QUESTION IS:
> |
> | is As["coef"] . vector_value() . fortran_vec() illegal?
> | or is this a bug?
> | or am I doing something wrong
> 
> I think either approach should work.  I created a simple test example
> and it worked fine.  Perhaps there is another problem in your code
> that causes a memory overwrite.  Can you please send me a complete
> example that demonstrates the problem?

I've gone over my code with a fine tooth(ed?) comb, and
I'm finding that for both

double * x= A["blah"] . vector_value() . data();
double * x= A["blah"] . vector_value() . fortran_vec();

x[0] is often corrupted. Sometimes this code segfaults, also.

I think that vector_value() creates a temprorary copy and
gives the pointer to data(), and then this copy is freed,
corrupting the first element, and invalidating references
to the memory.

Does this make sense?

andy



reply via email to

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