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

[WIP] pmr container adopt #110

Closed
wants to merge 1 commit into from
Closed

Conversation

mkrzewic
Copy link
Contributor

this is to keep the discussion on container adoption open, contains the full code form the original pr #93

/// Return a vector of const ElemT, takes ownership of the message
template<typename ElemT>
std::vector<const ElemT, OwningMessageSpectatorAllocator<const ElemT>>
getVector(size_t nelem, FairMQMessagePtr message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so this is the intended interface. I'd vote strongly against inclusion of it because:

  • The return type name is very long and I expect nobody to be able to spell it out. auto can help, but not so much when you want to store it as a data member.
  • Users still see std::vector in the type and expect it to behave like a vector. I.e. push_back, reserve, and other operations that reallocate must work correctly. IIUC that's not the case.
  • A simple new type with begin, end, operator[], and size() that takes ownership of the message and provides an STL interface to read-only access seems easier to create than the current solution (begin and end could simply return a pointer, no need for a full-blown iterator type) and involves no UB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I agree that custom containers that would allow direct adoption would be ideal, standard containers are just not designed to do this. One could try to make it work better (I think it would be possible to get the full expected functionality), but given the fact that gcc8 does not like this (libstdc++ static_asserts that T is not cv) this specific implementation has to go (or grow) anyway. I don't quite understand the need for this assertion as some functionality simply works with const elements, but they decided to start enforcing the requirement for T to be erasable, maybe for consistency.
I still think this is a useful exercise as I like the idea of containers that take ownership of the message together with the data so no additional book keeping is needed along the data path. I'll definitely give it more thought :)

  • about the long type names - if we are to use allocators, the type names will be long anyway:)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the need for this assertion as some functionality simply works with const elements

You already answered your question. ;-)

if we are to use allocators, the type names will be long anyway

Unless we start using std::pmr::vector consistently.

@codecov
Copy link

codecov bot commented Dec 13, 2018

Codecov Report

Merging #110 into dev will decrease coverage by 3.24%.
The diff coverage is 86.95%.

@@            Coverage Diff            @@
##              dev    #110      +/-   ##
=========================================
- Coverage   75.15%   71.9%   -3.25%     
=========================================
  Files          66      71       +5     
  Lines        3916    4051     +135     
=========================================
- Hits         2943    2913      -30     
- Misses        973    1138     +165
Impacted Files Coverage Δ
fairmq/shmem/FairMQTransportFactorySHM.h 100% <ø> (ø) ⬆️
fairmq/zeromq/FairMQTransportFactoryZMQ.h 100% <ø> (ø) ⬆️
fairmq/FairMQTransportFactory.h 100% <ø> (ø) ⬆️
fairmq/FairMQDevice.h 75% <ø> (-6.82%) ⬇️
fairmq/nanomsg/FairMQTransportFactoryNN.h 100% <ø> (ø) ⬆️
fairmq/FairMQMessage.h 0% <0%> (ø) ⬆️
fairmq/shmem/FairMQTransportFactorySHM.cxx 82.5% <100%> (+0.44%) ⬆️
fairmq/zeromq/FairMQTransportFactoryZMQ.cxx 75% <100%> (+1.19%) ⬆️
fairmq/FairMQDevice.cxx 76.29% <100%> (-4.04%) ⬇️
fairmq/zeromq/FairMQMessageZMQ.cxx 63.44% <100%> (-13.11%) ⬇️
... and 57 more

1 similar comment
@codecov
Copy link

codecov bot commented Dec 13, 2018

Codecov Report

Merging #110 into dev will decrease coverage by 3.24%.
The diff coverage is 86.95%.

@@            Coverage Diff            @@
##              dev    #110      +/-   ##
=========================================
- Coverage   75.15%   71.9%   -3.25%     
=========================================
  Files          66      71       +5     
  Lines        3916    4051     +135     
=========================================
- Hits         2943    2913      -30     
- Misses        973    1138     +165
Impacted Files Coverage Δ
fairmq/shmem/FairMQTransportFactorySHM.h 100% <ø> (ø) ⬆️
fairmq/zeromq/FairMQTransportFactoryZMQ.h 100% <ø> (ø) ⬆️
fairmq/FairMQTransportFactory.h 100% <ø> (ø) ⬆️
fairmq/FairMQDevice.h 75% <ø> (-6.82%) ⬇️
fairmq/nanomsg/FairMQTransportFactoryNN.h 100% <ø> (ø) ⬆️
fairmq/FairMQMessage.h 0% <0%> (ø) ⬆️
fairmq/shmem/FairMQTransportFactorySHM.cxx 82.5% <100%> (+0.44%) ⬆️
fairmq/zeromq/FairMQTransportFactoryZMQ.cxx 75% <100%> (+1.19%) ⬆️
fairmq/FairMQDevice.cxx 76.29% <100%> (-4.04%) ⬇️
fairmq/zeromq/FairMQMessageZMQ.cxx 63.44% <100%> (-13.11%) ⬇️
... and 57 more

@mkrzewic
Copy link
Contributor Author

here's another go at this still trying to use std::vector - now the adopted vector is not const and fully functional, but still with a special allocator.

@dennisklein
Copy link
Member

here's another go at this still trying to use std::vector - now the adopted vector is not const and fully functional, but still with a special allocator.

Thx, will have a look at it soon.

Also found this library: https://github.com/foonathan/array

@dennisklein
Copy link
Member

So far, I am not convinced that buffer adoption with std::vector is something we should do, so closing this. Feel free to reopen, if any new ideas/variations came up.

@dennisklein dennisklein closed this Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants