Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependency injection through process_event() to save sm memory footprint #589

Open
zhuoqiang opened this issue Aug 16, 2023 · 2 comments
Open

Comments

@zhuoqiang
Copy link

zhuoqiang commented Aug 16, 2023

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 ...

@krzysztof-jusiak
Copy link
Collaborator

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

@zhuoqiang
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants