Skip to content

How to safely transfer data when resizing publisher slots? #42

@mikael-s-persson

Description

@mikael-s-persson

This is either a question or a feature request. Say I want to publish messages with some dynamically-sized zero-copy thing like flatbuffers which doesn't have a known size but a "realloc" hook to reallocate the memory that it aliases for storing the fields. The obvious way to use this on top of subspace is to use "GetMessageBuffer" to allocate the memory that flatbuffer fills with data as the message is built. And then, when we reach the capacity (slot_size), we can call "GetMessageBuffer" again to get a bigger slot (and resize the channel). But, as I understand it, the previously obtained message buffer is potentially invalidated (ref-count decremented, might get unmapped or closed), and so, the reallocation would need to first copy whatever data has already been put in the old message buffer to some temporary location (heap), then call "GetMessageBuffer" with the bigger size, and finally, copy the memory back.

Is that right?

If so, it might be nice to have some ref-counted scheme similar to the subscriber's "shared-ptr" messages to keep the old message buffer alive a bit longer to avoid the double-copy.

Of course, resizing would only happen a handful of times early on, so, it's not a huge problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions