[erlang-questions] clarify: Sending big messages

Kostis Sagonas <>
Wed Oct 22 15:35:35 CEST 2008


Zoltan Peter Toth wrote:
> Hi,
> 
> We have a function like this:
> 
> deliver(Port, Data) ->
>     Port ! {data, Data}.
> 
> This function returns Data.

Nope.  This function returns {data, Data}.

I personally think that !/2 returning a value instead of being void as 
it should, is a design flow in the definition of the language. (*)

> Let's assume we want to send a big binary. If we call deliver(Port, 
> BigBinary), is there any performance
> penalty that results from handling the return value (that equals 
> BigBinary) ?
> 
> Can it cause extra CPU/memory consumption later on e.g. during garbage 
> collection ?

The time overhead is minimal, if any.

> I.e. is it worth changing deliver() to return just ok ?
> (This would be probably a good idea if this function is invoked via rpc.)

It's not only worth, but it is actually a very good idea.  It's not 
kosher having functions that you essentially treat as void returning 
things.  The dialyzer option -Wunmatched_returns warns about this.

Kostis


(*) The only reason I could possibly see for this happening is that one 
can implement broadcast using P1 ! P2 ! ... ! Pn ! Msg, but I've yet to 
come across a program that uses the above idiom... Has anybody seen one?




More information about the erlang-questions mailing list