[DPL] Support for resizable DataChunk#1846
[DPL] Support for resizable DataChunk#1846matthiasrichter wants to merge 2 commits intoAliceO2Group:devfrom
Conversation
92a7ff6 to
ad180b6
Compare
ad180b6 to
134d444
Compare
134d444 to
392a1f9
Compare
07395ee to
f225104
Compare
|
I have updated the PR and solved the task list. This introduces resizable Have studied three options, just to summarize here:
None of them is optimal. Option 2) A bit more cumbersome code, and no option which can be applied to PODs, otherwise quite ok Option 3) would work very nicely also for the In the end it's a question of |
|
Thank you for the nice write-up. For 3) if you use Anyways, I would go for 2), as 1) is a bit too drastic IMHO, we can always introduce it later on. Another possibility would be to use a To summarise I would go for what I consider the most local change (2) and then expand, once we make up our mind. |
f225104 to
067e294
Compare
Change DataChunk to be of type std::vector<char, o2::pmr::polymorphic_allocator> Interface changes: - makeChunk returns reference to std::vector<char> object with polymorphic_allocator - return value of adoptChunk is dropped, not possible to preserve this, not been used anyhow This goes in line with the general idea of DataAllocator's `make` methods, where the object is booked with one single call and is send automatically after processing ends. Requires return by reference and to use a reference variable in the code. The disadvantage is that accidental copy is possible and impossible to detect at compile time. Details: Introducing VectorObject to MessageContext, holding an instance of a vector. The memory is directly allocated in the message memory using the pmr functionality. In order to avoid that objects go out of scope and the allocated buffer is available at send, the created vector can not be returned by move, but is kept in the context and returned by reference. This requires changes in the code to use the reference instead of a copy. The return value of adoptChunk must be dropped because a buffer can only be adopted to a vector object using a special allocator. With this it can not simply be returned as it is a different type. Using polymorphic_allocator even for trivially default constructible types still invokes the constructor for the elements, thus changing the memory of the underlying resource.
Make DataChunk a class deriving from std::vector instead of an alias. This allows to delete the copy constructor and assignment operator. DPL's output allocator returns the created DataChunk by reference and thus it's important not to make a copy in the code. Now it's ensured to detect this at compile time.
067e294 to
5fb8d96
Compare
|
Can not access CI results from this PR any more, will open another one |
Change
DataChunkto bestd::vector<char, o2::pmr::polymorphic_allocator>Interface changes:
This goes in line with the general idea of DataAllocator's
makemethods, where theobject is booked with one single call and is send automatically after processing ends.
Requires return by reference and to use a reference variable in the code. The disadvantage
is that accidental copy is possible and impossible to detect at compile time.
Details:
Introducing VectorObject to MessageContext, holding an instance of an o2::vector.
The memory is directly allocated in the message memory using the pmr functionality.
In order to avoid that objects go out of scope and the allocated buffer is available
at send, the created vector can not be returned by move, but is kept in the context
and returned by reference. This requires changes in the code to use the reference
instead of a copy.
The return value of adoptChunk must be dropped because a buffer can only be adopted
to a vector object using a special allocator. With this it can not simply be returned
as it is a different type. Using polymorphic_allocator even for trivially default
constructible types still invokes the constructor for the elements, thus changing
the memory of the underlying resource.
TODO:
DataHeaderbefore sendingstd::vectorwithpolymorphic_allocatorin favor ofo2::vectormakeChunkis not copied to local variable - not in this PR requires more effort, see [DPL] Support for resizable DataChunk #1846 (comment)makeforo2::vector<T>- not in this PR