You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ptr is allocated in the shared memory (using Allocator) and given to the user. We also assign an Element in the shared queue to ptr. We hold a writer lock on this element until ptr is published. We may need to update the base Element to add an extra field: is_zero_copied, so that the consumer can react accordingly.
auto obj = new (ptr) SomeClass( /* params */);
// update obj
p.zero_copy_publish(ptr); // releases the shared queue element lock
On the consumer side, we'll return a subclass of Memblock: ZeroCopyMemblock which will not have a no_delete() and will be deallocated at the end of the callback. We'll need to check the logic for locks as well.
Code path for copied-communication:
// element is the currently accessed shared queue position
Memblock memblock;
element.lock.acquire();
memcpy(element.ptr, memblock.ptr, element.size);
memblock.size = element.size;
element.lock.release();
callback(memblock);
if (memblock.should_free) {
delete memblock;
}
The above has been shown for pub-sub, but they can be extended to RPC too.
Here's a problem, we can't free each message pointer independently. A message pointer can only be free after all preceding message allocations are released, which is due to the logic in which Allocator works. It is a strictly FIFO-based allocation strategy. For performance, we may want to consider moving to a more complex general-purpose allocator.
NOTE: Writing a general-purpose allocator to work on a single chunk of shared memory is very error-prone.
The text was updated successfully, but these errors were encountered:
I discovered your lib because my thought was, if I cannot manage memory across process (without writing a custom memory allocator) what can I do to go faster than memcopy.
Here's one way to achieve this:
ptr
is allocated in the shared memory (usingAllocator
) and given to the user. We also assign an Element in the shared queue toptr
. We hold a writer lock on this element untilptr
is published. We may need to update the baseElement
to add an extra field:is_zero_copied
, so that the consumer can react accordingly.On the consumer side, we'll return a subclass of
Memblock
:ZeroCopyMemblock
which will not have ano_delete()
and will be deallocated at the end of the callback. We'll need to check the logic for locks as well.Code path for copied-communication:
New code path for zero-copy communication:
The above has been shown for pub-sub, but they can be extended to RPC too.
Here's a problem, we can't free each message pointer independently. A message pointer can only be free after all preceding message allocations are released, which is due to the logic in which
Allocator
works. It is a strictly FIFO-based allocation strategy. For performance, we may want to consider moving to a more complex general-purpose allocator.NOTE: Writing a general-purpose allocator to work on a single chunk of shared memory is very error-prone.
The text was updated successfully, but these errors were encountered: