@@ -29,64 +29,16 @@ namespace allocator
29
29
template <typename T, typename Alloc>
30
30
using AllocRebind = typename std::allocator_traits<Alloc>::template rebind_traits<T>;
31
31
32
- template <typename Alloc>
33
- void * retyped_allocate (size_t size, void * untyped_allocator)
34
- {
35
- auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
36
- if (!typed_allocator) {
37
- throw std::runtime_error (" Received incorrect allocator type" );
38
- }
39
- return std::allocator_traits<Alloc>::allocate (*typed_allocator, size);
40
- }
41
-
42
- template <typename Alloc>
43
- void retyped_deallocate (void * untyped_pointer, void * untyped_allocator)
44
- {
45
- auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
46
- if (!typed_allocator) {
47
- throw std::runtime_error (" Received incorrect allocator type" );
48
- }
49
- auto typed_ptr = static_cast <typename Alloc::value_type *>(untyped_pointer);
50
- std::allocator_traits<Alloc>::deallocate (*typed_allocator, typed_ptr, 1 );
51
- }
52
-
53
- template <typename Alloc>
54
- void * retyped_reallocate (void * untyped_pointer, size_t size, void * untyped_allocator)
55
- {
56
- auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
57
- if (!typed_allocator) {
58
- throw std::runtime_error (" Received incorrect allocator type" );
59
- }
60
- auto typed_ptr = static_cast <typename Alloc::value_type *>(untyped_pointer);
61
- std::allocator_traits<Alloc>::deallocate (*typed_allocator, typed_ptr, 1 );
62
- return std::allocator_traits<Alloc>::allocate (*typed_allocator, size);
63
- }
64
-
65
32
} // namespace allocator
66
33
67
- // Deprecated: Generic converter from C++ allocator into RCL allocator.
68
- // This allocator overallocates memory by 100x and invokes UB on free,
69
- // see #1254.
70
- template <typename Alloc>
71
- rcl_allocator_t get_rcl_allocator (Alloc & allocator)
72
- {
73
- rcl_allocator_t rcl_allocator = rcl_get_default_allocator ();
74
- #ifndef _WIN32
75
- rcl_allocator.allocate = &allocator::retyped_allocate<Alloc>;
76
- rcl_allocator.deallocate = &allocator::retyped_deallocate<Alloc>;
77
- rcl_allocator.reallocate = &allocator::retyped_reallocate<Alloc>;
78
- rcl_allocator.state = &allocator;
79
- #else
80
- (void )allocator; // Remove warning
81
- #endif
82
- return rcl_allocator;
83
- }
84
-
85
34
// Builds the RCL default allocator for the C++ standard allocator.
86
35
// This assumes that the user intent behind both allocators is the
87
36
// same: Using system malloc for allocation.
37
+ //
38
+ // If you're using a custom allocator in ROS, you'll need to provide
39
+ // your own overload for this function.
88
40
template <typename T>
89
- rcl_allocator_t get_rcl_allocator (std::allocator<T> & allocator)
41
+ rcl_allocator_t get_rcl_allocator (std::allocator<T> allocator)
90
42
{
91
43
(void )allocator; // Remove warning
92
44
return rcl_get_default_allocator ();
0 commit comments