Re: Pass by reference for compiled functions
- To: mathgroup at smc.vnet.net
- Subject: [mg114304] Re: Pass by reference for compiled functions
- From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
- Date: Tue, 30 Nov 2010 04:05:57 -0500 (EST)
On Mon, 29 Nov 2010, Eric Michielssen wrote: > For noncompiled functions, one can pass arguments "by reference" and then > modify them inside the routine by assigning the function the attribute > HoldAll. > > This does not work for compiled functions: it does not appear possible to > modify arguments to compiled functions, even if they are passed as "global > variables". That is, Mathematica responds to > > Myfunction = Compile[ > {{var1,_Real}}, > Module[{}, > Modify var 1 or var2; > Return[]], {var2,_Real}]; > > With > > Compile::argset: The assignment to var1 is illegal; it is not valid to > assign a value to an argument. >> And something similar for var2. > > HoldAll does not seem to apply here... > > This makes it memory-inefficient to modify large arrays in compiled > functions, as one would have to operate on a copy of the array. > > Is there a workaround in Mathematica 8? a workaround could be to use LibraryFunctionLoad and use the "Shared" attribute. Oliver > > Eric Michielssen > > > >