-
Notifications
You must be signed in to change notification settings - Fork 418
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
Keep custom allocator in publisher and subscription options alive. #1647
Changes from all commits
0f768bb
f4dcd4e
6ff1246
fe13993
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include <list> | ||
#include <memory> | ||
#include <string> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "test_msgs/msg/empty.hpp" | ||
|
@@ -57,7 +58,10 @@ struct MyAllocator | |
return nullptr; | ||
} | ||
num_allocs++; | ||
return static_cast<T *>(std::malloc(size * sizeof(T))); | ||
// Use sizeof(char) in place for sizeof(void) | ||
constexpr size_t value_size = sizeof( | ||
typename std::conditional<!std::is_void<T>::value, T, char>::type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is fine. I spent some time looking at libcxx's code and I couldn't find anything in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was actually hoping to find something on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is also a new warning in all builds, likely related to this: https://ci.ros2.org/view/nightly/job/nightly_linux-aarch64_debug/1593/gcc/new/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same root cause. |
||
return static_cast<T *>(std::malloc(size * value_size)); | ||
} | ||
|
||
void deallocate(T * ptr, size_t size) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think this was a mistake. From
cppreference
:It appears
void
allocators are not supposed to be used for anything but type-erasure. If everything complies with that i.e. no code attempts to callallocate
on avoid
allocator, then you can afford not making the explicit specialization like the test allocator, the allocator tutorial and now the tlsf allocator do...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you fix that one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tlsf_cpp
? We could, but I'm starting to think we shouldn't be asking custom void allocators to have char-like allocate/deallocate APIs. Even if they were written carelessly (with no explicit specialization forvoid
) and have them, chances are it won't build. See #1657.