File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
demo_nodes_cpp/src/topics Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,33 @@ constexpr bool operator!=(
9292 return false ;
9393}
9494
95+ // You need to overload get_rcl_allocator for custom allocators.
96+ // This function needs to build an instance of rcl_allocator_t
97+ // for use in C code.
98+ template <typename T>
99+ rcl_allocator_t get_rcl_allocator (MyAllocator<T>)
100+ {
101+ rcl_allocator_t rcl_allocator;
102+ rcl_allocator.allocate = [](size_t size, void *) {
103+ num_allocs++;
104+ return malloc (size);
105+ };
106+ rcl_allocator.deallocate = [](void * pointer, void *) {
107+ num_deallocs++;
108+ return free (pointer);
109+ };
110+ rcl_allocator.reallocate = [](void * pointer, size_t size, void *) {
111+ num_allocs++;
112+ num_deallocs++;
113+ return realloc (pointer, size);
114+ };
115+ rcl_allocator.zero_allocate = [](size_t nmemb, size_t size, void *) {
116+ num_allocs++;
117+ return calloc (nmemb, size);
118+ };
119+ return rcl_allocator;
120+ }
121+
95122// Override global new and delete to count calls during execution.
96123
97124static bool is_running = false ;
You can’t perform that action at this time.
0 commit comments