cost of passing a gen_server state between functions

Pablo Platt <>
Sun Aug 8 03:21:16 CEST 2010


Hi,

Is there a difference in manipulating the state of a gen_server inside a single 
function
and passing the state to another function that manipulate it?
Is there a difference if the othe function is in another module?

%The state is been manipulated in the handl_cast function:
handle_cast({something, I}, State1) ->
    OldList = State1#state.l,
    NewList = [I | OldList],
    State2 = State#state1{l=NewList},
    {noreply, State2}.

%handle_cast pass the state to another function that changes it:
handle_cast({something, I}, State) ->
    State2 = do_something(I, State),
    {noreply, State2}.
    
do_something(I, State) ->
    State2 = State#state1{l=NewList},
    State2.

Thanks



      


More information about the erlang-questions mailing list