help-octave
[Top][All Lists]
Advanced

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

Re: Realtime cost of call by value


From: Geraint Paul Bevan
Subject: Re: Realtime cost of call by value
Date: Wed, 29 Oct 2003 00:16:47 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

address@hidden wrote:

|
|      I think that there were hints that newer versions of Octave will
| have "handles", or "references" to data.

If you don't mind using pointers, it is possible to create handles to
Octave objects within .oct files and to pass them around within Octave
as integers (or structures perhaps if you have very large address space
or want to retain meta-data about the object).

This is very ugly and does mean that you have to free (with delete) the
memory associated with the pointers when you have finished with them,
but it should be effective at eliminating the pass by value problem if
you have a lot of data. Just pass the integer to your function and allow
it to dereference it from within the function.


// -*-c++-*-
// create_ptr.cc

#include <octave/oct.h>
#include <octave/parse.h>

DEFUN_DLD(create_ptr, args, , "create pointer")
{
~  octave_value *p;

~  p = new octave_value(feval(args));

~  return octave_value(reinterpret_cast<int>(p));
}


// -*-c++-*-
// dereference_ptr.cc

#include <octave/oct.h>

DEFUN_DLD(dereference_ptr, args, , "dereference pointer")
{
~  int i = args(0).int_value();

~  octave_value *p = reinterpret_cast<octave_value *>(i);

~  return *p;
}



octave> ptr = create_ptr("rand", 3, 3)
ptr = 143864368

octave> dereference_ptr(ptr)
ans =
(
~  [1] =

~    0.078211  0.277522  0.237845
~    0.612765  0.659463  0.997766
~    0.357452  0.306368  0.304478

)
- --
Geraint Bevan
http://homepage.ntlworld.com/geraint.bevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAj+fBu0ACgkQcXV3N50QmNMaAgCdGu1sGK7otE77lD69UewNMzw/
JeAAn1R2m9S4gDR5m+W7GMiqyOEVYCDD
=fQy5
-----END PGP SIGNATURE-----



-------------------------------------------------------------
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]