|
Boost Users : |
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2008-06-04 13:03:15
> > 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.
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