help-octave
[Top][All Lists]
Advanced

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

Re: [] indexing of Array type.


From: Quentin Spencer
Subject: Re: [] indexing of Array type.
Date: Mon, 21 Nov 2005 12:26:38 -0600
User-agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929)

John W. Eaton wrote:

On 21-Nov-2005, Quentin Spencer wrote:

| I'm writing a function in C that I would like to make available to an | other program without requiring the octave headers, so I'm writing an | octave wrapper around it. I'd like to be able to create an octave array | of the size I want, and then pass a pointer to the data within the array | to the external function so that the external function does not require | octave headers. I have been able to do something like this: | | RowVector x(SIZE);
| const double* y=x.data();
| external_func(y);
| | However, this gives read-only access to the data (it won't compile | unless y is declared as a const double*). Suppose I want to create an | external_func(const double* y, double* z) that takes y as input, and | puts values in z. The only way I've successfully done this so far is by | creating the array and then copying the results into an octave Array | type in the wrapper function, which seems like unnecessary overhead. Is | there any way I can just access the pointer directly using the data | member function without making the declaration a const?

You want the fortran_vec() method instead of data().  That will also
ensure that the reference count of the data you are passing is just one.

Thanks. That did it! If only I'd looked about 400 lines further down in Array.h the first time... :)

-Quentin



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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