[Top][All Lists]

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

Re: Oct files: How to get read-only pointers to data for arguments of un

From: Stefan
Subject: Re: Oct files: How to get read-only pointers to data for arguments of unknown type?
Date: Tue, 28 Feb 2012 08:23:11 -0800 (PST)


Thanks for your help.

| You are casting away const here, so you may see some unexpected 
| results. 
| For example, try 
| x = y = 1+i; 
| oct_test (x)

The data behind both x and y will be modified by oct_test(), since x is so
far used only as a pointer to y. I don't find this unexpected. Or this:

x = y = 1+i
y = 1+2*i

The data in y will not be modified, since y points to a different object
now. Just what one expects in a "lazy copy" language.

My applications are usually memory critical. Consider the memory needs of:

my_huge_matrix = octfile(my_huge_matrix)

Here, octave makes a copy of my_huge_matrix at the call of octfile, and then
copies the result back to the workspace. So 3 copies of my_huge_matrix must
fit into memory. It is particularly annoying if the memory error comes only
after the expensive calculation is completed. In pass-by-reference, once I
succeed to fit the initial matrix into memory, I know that the result will
fit as well.

This is of course the same problem in matlab. Only, since matlab mex is in
C, it was easier to get pass-by-reference behavior for mex files. In
octave's C++ API, everything is overloaded and has side effects, so you
never know which seemingly harmless statement causes a copy of the data
behind the scenes. (On a side note, I always thought that a simple void* in
C is vastly superior to C++ templates. Why all the copy-paste source files
like,,, ... ?)

There could be a mechanism to attach an attribute to a variable that should
be passed by reference, like IDL's TEMPORARY mechanism. Something like this
might be a good idea.

Thanks for the discussion,


View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

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