
Hi, I haven't yet looked at MSM. However, I do wonder if the activity/state diagrams generated from MSM based code would be convertible to equivalent sequence diagrams. In other words, I want to know if MSM does indeed create object instance and whether it creates those instances on heap, etc. In short, I am interested in the performance aspect. I have a scenario where I have two state machines - basically, protocols for the trading domain - and I am supposed to map one protocol to another and vice versa - that is, develop a message broker. I am thinking about designing a generic solution that could be used to map any protocol (all messages along with their behavior) to any protocol based on the grammar - the message strings, their sequences, etc. Can I use MSM for this kind of a problem? I did write something like this for a client a long time back but it would take me quite some time if I jump into doing that again. That does make think if Boost MSM (or StateChart?) offers a faster solution. Thanks in advance, -Asif

Hi,
On Wed, Oct 19, 2011 at 13:50, asif saeed
That does make think if Boost MSM (or StateChart?) offers a faster solution.
I'm not a specialist nor very experimented with the library but the following information might help: When you instantiate an MSM state machine, all the states are created at the same time, like member objects. I don't know if its the case or if they are dynamically allocated but they are all built from the start. On transition, on_exit and on_entry members of states will be called. It means you can even keep values in states for longer than their activation. Theorically, you can even make your whole state machine copyiable (I might be wrong though). There is just a compiler bug with MSVC that makes it impossible to put in a std::vector, as I tried to do in an experiment, but other than that it's what you would expect from simple types. The transitions from all the state machine is defined in one unique point, the transition table, making easy to see what can happen in one read. Statechart will work very differently and certainly really less efficiently for you. Statechart will instantiate a state machine with one initial state but not more at first. On each transition, the states from which you come from will be destroyed and the states where you go will be instantiated "on the fly", making constructor and destructor the only points where you know that you enter and exit states. Also, parent states of sub states are kept alive if a transitions happen between substates, but will be destroyed once you go to a state outside the parent state -- it feels natural, knowing the instantiation logic. Each statechart state type will provide a set of possible transitions, making easy to know where you can go from one state, but harder to see the "big picture". If I'm wrong somewhere in these descriptions, please allow me to know. Hope it helps. Joël Lamotte

Each statechart state type will provide a set of possible transitions, making
easy to know where you can go from one state, but harder to see the "big
picture".
If I'm wrong somewhere in these descriptions, please allow me to know.
Hope it helps.
>Joël Lamotte Hi, small note: this is also possible with msm (but not my favorite choice, which might explain why it's so well hidden ;-) ). You can use the row2's for this. See: http://www.boost.org/doc/libs/1_47_0/libs/msm/doc/HTML/ch03s02.html#d0e807. There is a small note at the end of this internal transition table chapter with an example how to replace the transition table with internal tables inside every state. But really, if you use this, you'll pretty fast get ugly code (every state knowing other states) so I won't advise this. Regards, Christophe

Hi,
I haven't yet looked at MSM. However, I do wonder if the activity/state diagrams
generated from MSM based code would be convertible to equivalent sequence
diagrams. In other words, I want to know if MSM does indeed create object instance
and whether it creates those instances on heap, etc. In short, I am interested in the
performance aspect. I have a scenario where I have two state machines - basically,
protocols for the trading domain - and I am supposed to map one protocol to another
and vice versa - that is, develop a message broker. I am thinking about designing a
generic solution that could be used to map any protocol (all messages along with
their behavior) to any protocol based on the grammar - the message strings, their
sequences, etc. Can I use MSM for this kind of a problem? I did write something
like this for a client a long time back but it would take me quite some time if I jump
into doing that again. That does make think if Boost MSM (or StateChart?) offers a
faster solution.
Thanks in advance,
-Asif
Hi, MSM creates all states on the stack for better performance. Actually, msm does not know the word "new" ;-) The only things which can use the heap are the queues (which you can customize / disable). What Joel wrote is also correct: all states are created on the stack upon fsm construction and stay around until destruction, the state machine is copyable (and even serializable/deserializable, which might help if you want to send them as a string along the message). I'm not sure I fully understand your problem but as a small note, state machines and sequence diagrams are not equivalent (sequence diagrams do not have the "specification" capability). What you also need to know is that with msm, a state machine structure has to be known at compile-time, you cannot design it at run-time depending on a concrete message data. Something like "if(...) fsm.add_transition(...))" is not possible. HTH, Christophe
participants (3)
-
asif saeed
-
Christophe Henry
-
Klaim - Joël Lamotte