Passing Dynamically sized data to server

24 views
Skip to first unread message

Tanzeela Younas

unread,
Dec 29, 2021, 12:54:14 AM12/29/21
to actor-framework
Without using string, How can I pass data to the server  if length of my data is variable i.e char *.... Something like Like below...


behavior server() {
  return {
      [ = ](print_atom, char * data , int b) {
                aout (self)  << data << b << endl;
        },
    };
}

It gives some unexpected error.....

Dominik Charousset

unread,
Dec 30, 2021, 5:20:02 AM12/30/21
to actor-f...@googlegroups.com
CAF is built with concurrency and distribution in mind. Passing around pointers in messages is almost always a recipe for disaster since there is no intrinsic way to track ownership or to copy the data when necessary.

If you'd like to avoid std::string, you could use a std::vector or some other buffer type. But simply passing around pointers won't work unless you have a buffer that somehow is guaranteed to outlive the actor system and you plan to never distribute your actors beyond a single process. In this case, you can probably just use a static buffer to begin with, though.

Hope that helps,
Dominik

Reply all
Reply to author
Forward
0 new messages