MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: By Reference

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105440] Re: By Reference
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Wed, 2 Dec 2009 06:28:56 -0500 (EST)
  • References: <hf2mrq$ie9$1@smc.vnet.net>

snirga wrote:
> Hi All,
> 
> I am implementing a "call by reference" in Mathematica using HoldFirst
> in order to send a huge matrix into a function.
> 
> I wanted to verify that Mathematica doesn't create a memory copy of
> this matrix once it is being sent to the function.
> 
> Thanks
> 
> Snir
> 

I presume your function is intended to modify elements of the array - 
otherwise no copy is likely to take place. Defining a function such as:

SetAttributes[foo,HoldFirst]

foo[arr_Symbol]:=Module[{},
..
..
..
arr[[j]]=42;

..
..
last operation;
]

should do what you want. Note that your function is modifying the 
original array directly, and so should not pass back a return value 
(well not the array value at any rate).

Note that you can use MemoryInUse to explore what is happening, but you 
must be careful not to get copies of the array in your history.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: ListPointPlot3D[] couldn't rotate the graph
  • Next by Date: Efficiently compute Fourier coefficients for discrete function
  • Previous by thread: Re: By Reference
  • Next by thread: vector format rendering with gradient capabilities