help-octave
[Top][All Lists]
Advanced

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

Re: External C DLL crashes Octave


From: mishrapiyush
Subject: Re: External C DLL crashes Octave
Date: Fri, 28 Aug 2009 14:15:25 -0700 (PDT)

Thank you Jaroslav and John. "double* A = B.fortran_vec()" worked like a
charm! Just out of curiosity, I also tried type casting "double* A = (double
*)B.data()" and that seems to work as well, but I have decided to go with
fortran_vec. I also found that I was passing array in row-major format while
Matlab and Fortran work on column-major format, so I had to pass transpose
of original Matrix to ensure correct execution.

John, the reason I am converting the pointer to double * is compatibility of
my cpp code - to use the same code on both Matlab and Octave until I am
confident of the port. But, I want to ask you guys if I can return an array
of double from my function as well? Can I just say:

func1(C, A);
retval(0) = C;

where C is a pointer to doubles.

Thanks,
Piyush
  

John W. Eaton-3 wrote:
> 
> On 28-Aug-2009, Jaroslav Hajek wrote:
> 
> | On Fri, Aug 28, 2009 at 9:44 PM, mishrapiyush<address@hidden> wrote:
> | >
> | > Tatsuro,
> | >
> | >  Thanks for replying to promptly.. I am using Octave 3.2.0, which is
> the
> | > latest Win binary. I believe it is the MinGW version. I am able to
> compile
> | > and call the sample application (d_gcc) but was having problem with my
> Cpp
> | > code.
> | >
> | >   In the meantime, I have found the reason of crash - it was due to an
> | > error in my DEFUN_DLD function. Basically, I want to pass an array of
> | > Doubles to my C function, say, as follows:
> | > x = [10 100 1000 10000] %array of Doubles
> | > mycodewrapper(x) %containing func1
> | >
> | > as stated earlier, func1 is defined as follows:
> | > extern "C" unsigned int func1(double *x);
> | >
> | > I have tried:
> | > Matrix B = args(0).matrix_value();
> | > double* A = B.Rep->data;"
> | >  but rep is now protected and hence compilation fails.
> | >
> | > Could you recommend a good way to convert args of DEFUN_DLD into a
> pointer
> | > of doubles. Is there a variation on "double* A = B.data()" which will
> allow
> | > me to cast const double* to double*?
> | >
> | 
> | B.Rep->data would be wrong anyway. B.fortran_vec() correctly extracts
> | a writable pointer.
> 
> Jaroslav is correct, but does your function actually need to modify
> its argument?  If not, better to declare the argument "const double*"
> and then pas "B.data ()" to your function.  Also, arguments passed to
> Octave functions are strictly copy on write, so any modification you
> do make to the contents of B will not appear in the calling context
> unless you explicitly return the modified value as an output from your
> function.
> 
> jwe
> 
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

-- 
View this message in context: 
http://www.nabble.com/External-C-DLL-crashes-Octave-tp25189231p25197060.html
Sent from the Octave - General mailing list archive at Nabble.com.




reply via email to

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