Heap Allocator in ROS

In ROS 1 and ROS 2 the default allocators (new/delete, which are based on malloc and free) are not overridden by default.

In ROS 1 you can provide your own C++ style allocator for messages, but that’s about it.

In ROS 2 you can provide your own C++ style allocator for messages, publishers, subscribers, and the executor (the thing that does spin()). You can also provide a custom allocator when using the C api’s in ROS 2, using an allocator struct, but the default again uses malloc and free.

There are no nodelets in ROS 2, but you can compose multiple nodes into a single process in ROS 2, like you could with nodelets in ROS 1.

Composition of nodes, whether by nodelets in ROS 1 or with normal Nodes in ROS 2, has no bearing on the use of the default or custom allocators. The decision is orthogonal as far as I can see.

1 Like