|
Boost Users : |
Subject: Re: [Boost-users] [msm] Why does it take so many bytes to represent a state machine?
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2012-11-13 15:52:33
>Hi,
>
>I'm using msm to store the state of many small objects. Each one is around 24 bytes on its own. However, I just found out
>from experimentation that a MSM state machine takes many bytes to store. For the following program, the print out is:
>entering: State1
>104
>48
>This indicates that the very simple one-state, no-transition, machine is 104 bytes, and takes 48 bytes even to serialized.
>The front::state_machine_def, however, is only 1 byte, though I suspect thet real state is stored only
>in the 104-byte back::state_machine.
Hi Josh,
It depends on several factors:
- MSM creates all the states at state machine creation and the states live until the state machine is destroyed, so even if the states have no data, it'll be a byte per state.
- you need to keep the id of the current state in each region (int)
- 2 bool for internal implementation details
- a queue for deferred events if you have some in your fsm (if none, MSM will deactivate this, but you'll still pay 1 byte).
- an event queue (enabled by default but you can deactivate it if not needed (see http://svn.boost.org/svn/boost/trunk/libs/msm/doc/HTML/ch03s02.html#d0e1139) but it will still cost 1 byte.
Both queues are per default a std::deque, which can be expensive on some systems. You can choose another container if you wish (see http://svn.boost.org/svn/boost/trunk/libs/msm/doc/HTML/ch03s05.html#d0e2680).
As you see, if you remove the queues, there is not much more to take away.
Also note that a text archive brings its own costs.
HTH,
Christophe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net