sml icon indicating copy to clipboard operation
sml copied to clipboard

dependency injection through process_event() to save sm memory footprint

Open zhuoqiang opened this issue 2 years ago • 2 comments

currently there are 2 ways to inject dependencies:

  • sm::process_event(auto event) call, which only inject the event into the guard/action
  • sm constructor, which will inject extra context object to guard/action by storing the context inside sm object.

normally it works fine, however, in some use case, it would be great to iject the context object through method call instead of storing it in the object to save sm memory footprint.

for example, suppose there are tens of thousands of HTTP client state machine objects managered by a HTTP server. It is a waste of memory to store the same context pointer in each and every one of the sm object through its constructor. It is better to inject the context through method call, like process_event()

currently, only a single event object could be injected through process_event(). in this case we could still embeded the context pointer/reference inside the event object like sm.process_event(PingEvent{context}). It's functional, though not idea.

it could be great if sml could inject extra parameters passed into process_event, something like:

Context context;

sm.process_event(PingEvent{}, context);

or maybe in other ways, like:

sm.inject(context).process_event(PingEvent{});

or use a local proxy object

Injector{sm, context}.process_event(PingEvent{});

not sure if it doable ...

zhuoqiang avatar Aug 16 '23 15:08 zhuoqiang

Agree, I have a version somewhere where process event is accepting additional ts... parameters. Let me check...

kris-jusiak avatar Aug 16 '23 15:08 kris-jusiak

@krzysztof-jusiak Any luck finding the version with additional param in process_event()?

zhuoqiang avatar Aug 24 '23 02:08 zhuoqiang