-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add ability to pass in allocator for some methods #260
Comments
The destructor doesn't need an allocator, an allocator should be passed at construction time and stored by the implementation.
The general preference is to store the allocator internally, so it's obvious that the same allocator was used for construction and destruction. Between using the allocator in the context and being able to pass allocators individually, I'm not quite sure what's preferred. Though the API have allocators passed in some places, the rmw implementations aren't using it consistently.
My feeling is that allocation in rmw implementations needs a general cleanup, and that would require some discussion. |
I agree with the need for a general cleanup. Regarding |
The publisher destructor is receiving a pointer to the parent node, not an allocator (the original post mentioned that, because the allocator stored in the node could be used). In the case of allocators, I think we (almost) always stick it internally. Doing that avoids errors. In the case of
In this last case, I think that passing the pointer might be less error prone. The only problem is that we don't do that consistently (e.g rmw_destroy_node, rmw_destroy_guard_condition doesn't receive a context). |
IMO, passing individual allocators to the functions that may need them makes for a flexible design while allowing destroy functions to more easily keep track of what allocator was used. Like in |
If we decide to pass allocators individually, it'd be nice if the
Something to consider. |
The advantage of passing the allocator in both the constructor and destructor is that later you can easily use the same allocator with many objects without each of them having a copy of (or a reference to) the allocator. I'm not sure if it allows destroy functions to "more easily keep track" of what allocator was used. |
IMO, we should use the |
I don't know what the advantages are in typedef-ing the allocator; There's also this TODO (but I don't know the context behind it, no pun intended): rmw/rmw/include/rmw/init_options.h Lines 60 to 62 in 9f3c3e1
|
Feature request
Feature description
A couple of destruction methods have signatures that make it impossible to obtain an allocator from an active context, which means that any of the members those methods are meant to deallocate cannot use a user defined allocator to do so.
An example is the
rmw_destroy_guard_condition
I suspect there are a couple more, such as
rmw_destroy_wait_set
, etc.This could be done by either sticking the context or node pointer in the relevant structs, or passing it into the method like how
rmw_destroy_publisher
does it. Though this might be API breaking for all existing rmw implementations.Implementation considerations
On the other hand, I'm not sure if the recommended way to allocate or deallocate dynamic memory is via
rmw_allocate
andrmw_free
. It looks like those just boil down to amalloc
andfree
/delete
call.I presume that using allocators (that is,
rcutils_allocator_t
) would be preferable?The text was updated successfully, but these errors were encountered: