[statechart] usage in realtime application
Hi, I'm trying to convert a custom statemachine implementation in a real-time application to Boost.Statechart. The FAQ mentions that custom allocators have to be provided for Event, StateMachine etc. in order to get deterministic timing behaviour. I'm currently working on an allocator which uses an internal preallocated memory pool. Now my question is whether it is possible to determine how much memory i need to preallocate for the States and Events. Regards, Marc
Hi Marc
I'm trying to convert a custom statemachine implementation in a real-time application to Boost.Statechart. The FAQ mentions that custom allocators have to be provided for Event, StateMachine etc. in order to get deterministic timing behaviour. I'm currently working on an allocator which uses an internal preallocated memory pool. Now my question is whether it is possible to determine how much memory i need to preallocate for the States and Events.
Besides the obvious ones (storage for events & states, memory usage also depends on what features you use: event posting, history, etc.). It is theoretically possible to determine the exact memory requirements in advance but it's probably much easier to simply let the machine run through all possible states (e.g. with the unit tests you've written) and observe the amount of memory used. If that is not an option for you please let me know. HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
Hi Andreas
Hi Marc
I'm trying to convert a custom statemachine implementation in a real-time application to Boost.Statechart. The FAQ mentions that custom allocators have to be provided for Event, StateMachine etc. in order to get deterministic timing behaviour. I'm currently working on an allocator which uses an internal preallocated memory pool. Now my question is whether it is possible to determine how much memory i need to preallocate for the States and Events.
Besides the obvious ones (storage for events & states, memory usage also depends on what features you use: event posting, history, etc.). It is theoretically possible to determine the exact memory requirements in advance but it's probably much easier to simply let the machine run through all possible states (e.g. with the unit tests you've written) and observe the amount of memory used. If that is not an option for you please let me know.
Many thanks for your reply. That is actually a feasible solution for the long run, but at the moment I'm looking for something that allows me to automatically calculate the memory needed by the states and events. I think a reasonable upper limit for the states would be something like maximum_nesting_level * maximum_state_size. Is there anyway I could calculate this (or any other upper limit) automatically (i.e. not manually in the code)? I also wanted to ask about the event queue in state_machine. In my statemachine events will be posted internally as well as from an external source. Is there a way to force a certain limit on the number of events in the queue in order to be able to preallocate the right amount of memory? Thanks for your help, Marc
Besides the obvious ones (storage for events & states, memory usage also depends on what features you use: event posting, history, etc.). It is theoretically possible to determine the exact memory requirements in advance but it's probably much easier to simply let the machine run through all possible states (e.g. with the unit tests you've written) and observe the amount of memory used. If that is not an option for you please let me know.
Many thanks for your reply. That is actually a feasible solution for the long run, but at the moment I'm looking for something that allows me to automatically calculate the memory needed by the states and events. I think a reasonable upper limit for the states would be something like maximum_nesting_level * maximum_state_size.
Correct.
Is there anyway I could calculate this (or any other upper limit) automatically (i.e. not manually in the code)?
Not in general, no. In addition to the storage needed for events & states themselves, a state_machine<> subclass object contains various container data members (by value): 1. state list (std::list<>), max. size is equal to the number of orthogonal regions in your state machine 2. event queue (std::list<>), max. size is equal to the max. number of events posted during event processing 3. deferred events (std::map<>), max. size is equal to the total max. number of deferred events 4. history (std::map<>), max. size is equal to the number of states with history (deep or shallow) If the whole state machine is contained in the same translation unit, then you could theoretically calculate the sizes for 1 & 4 with some compile time magic. It's impossible to do that for 2 & 3, as those sizes could depend on information only available at runtime. Usually you can come up with an upper limit for 2 & 3 by manually going through the source code.
I also wanted to ask about the event queue in state_machine. In my statemachine events will be posted internally as well as from an external source. Is there a way to force a certain limit on the number of events in the queue in order to be able to preallocate the right amount of memory?
The library does not currently support such a limit. However, you could specialize your allocator so that allocations for the event queue are treated differently than other allocations. HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
participants (2)
-
Andreas Huber
-
Marc Ruiter