help-octave
[Top][All Lists]
Advanced

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

Re: avoiding copying arguments by value when calling a function


From: Sergei Steshenko
Subject: Re: avoiding copying arguments by value when calling a function
Date: Mon, 20 Aug 2012 07:01:28 -0700 (PDT)


--- On Mon, 8/20/12, Sergei Steshenko <address@hidden> wrote:

> From: Sergei Steshenko <address@hidden>
> Subject: avoiding copying arguments by value when calling a function
> To: address@hidden
> Date: Monday, August 20, 2012, 6:55 AM
> Hello,
> 
> if I understand correctly, if I write a function like this:
> 
> function result = foo(bar)
>   # function body goes here
> endfunction
> 
> and if I call the function this way
> 
> result = foo(bar);
> 
> , the 'bar' argument is copied by value each time 'foo' is
> called.
> 
> 
> I was thinking of something like this:
> 
> 
> bar_func = @() bar; # Octave accepts this
> 
> function result = foo(bar_func)
>   # function body goes here
>   # whenever I need 'bar' I use bar_func() instead
> endfunction
> 
> - I tried this and it works, i.e. produces the expected
> result.
> 
> If again I understand correctly, passing 'bar_func' is
> passing a function handle, which for large enough 'bar' data
> can hopefully yield better performance.
> 
> Are my understandings correct ? I.e. can anonymous functions
> be used as data wrappers in order to avoid physical copying
> of data ?
> 
> Thanks,
>   Sergei.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
> 

Or

bar_func = @() bar;

causes copying of 'bar' by value when 'bar_func' is called, so no performance 
gain is achieved ?

If that's the case, then what - global variables ?

Thanks,
  Sergei.


reply via email to

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