[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
avoiding copying arguments by value when calling a function
From: |
Sergei Steshenko |
Subject: |
avoiding copying arguments by value when calling a function |
Date: |
Mon, 20 Aug 2012 06:55:43 -0700 (PDT) |
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.
- avoiding copying arguments by value when calling a function,
Sergei Steshenko <=
- Re: avoiding copying arguments by value when calling a function, Michael Goffioul, 2012/08/20
- Re: avoiding copying arguments by value when calling a function, c., 2012/08/20
- Re: avoiding copying arguments by value when calling a function, Sergei Steshenko, 2012/08/20
- Re: avoiding copying arguments by value when calling a function, Jordi Gutiérrez Hermoso, 2012/08/20
- Re: avoiding copying arguments by value when calling a function, Carnë Draug, 2012/08/20
- Re: avoiding copying arguments by value when calling a function, Sergei Steshenko, 2012/08/22