[Tinyos-devel] call-by-value vs. -pointer

Philip Levis pal at cs.stanford.edu
Thu Jun 12 11:09:22 PDT 2008


On Jun 12, 2008, at 7:12 AM, Jan Hauer wrote:

> I'd like to hear people's opinion about passing
> command-/event-parameters by pointer vs. by value, in a situation
> where you would like to use call-by-value semantics, but the number of
> arguments / their total size is big. Background: some of the 802.15.4
> management primitives use a lot of parameters (in some situations 7
> parameters with a total of 25 byte) and there is generally a
> perfomance penalty when passing them by value over the stack (more
> code size, slower execution). One alternative is that the caller
> encapsulates the parameters in a struct and passes a pointer to it.
> The drawback is that one needs an agreement about when/how long the
> pointer is valid. When you have written the callee component yourself
> you can make sure that you keep no reference after the return
> statement, but when you cannot control the callee (e.g. signal an
> event to some app) passing a pointer can be problematic. As long as
> the interfaces are not used very frequently, I tend to prefer the
> call-by-value approach even if a long list of parameters is passed -
> what do other people think?

With the exception of allocators, TinyOS semantics tend to be:

For single-phase calls, ownership of a pointer is granted to the  
callee and given back to the caller when the call returns. (e.g.,  
Packet)

For split-phase calls, when ownership of a pointer is granted to the  
callee and given back to the caller when the completion event is  
signaled, the done event passes the pointer. (e.g., Send)

I can't think of any interfaces off the top of my head which are split- 
phase yet return ownership of the pointer when the command returns/

Phil




More information about the Tinyos-devel mailing list