Executing in constance space + memory usage

Joel Reymont <>
Wed Apr 20 17:07:38 CEST 2005


Is there a way to find out the memory used by a process? 

I found references to the various code profilers but the only thing I
know that reports memory usage is erlang:memory() and that is for the
emulator overall. 

I have a code like this:

wait_for_players(Game) ->
	Event ->
	    Game1 = dispatch(Game, Game#game.state, Event),

where dispatch is a series of function clauses to match game state and
event, including a final "catch all" clause. 

The code is part of the game process and I intend to have as many games
as possible. I wonder if it's ok for me to recursively call
wait_for_players from one of the dispatch clauses or if I should return
some error up to wait_for_players and call it recursively like I'm doing

It seems to me that the approach of having dispatch return will capture
less stack, i.e. the process will execute in less memory. This is just a
guess, I don't know how to prove it. 

Calling wait_for_players from one of the dispatch clauses makes the code
cleaner and would be my preferred approach. I would venture to guess that
it will increase the memory taken by the process quite a bit.

What's the best way to proceed? 

    Thanks, Joel


More information about the erlang-questions mailing list