-
Notifications
You must be signed in to change notification settings - Fork 422
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 "MemoryStrategy" to Executor with dep. injection #56
Conversation
{ | ||
namespace executor | ||
{ | ||
struct AnyExecutable |
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.
You could use the RCLCPP_MAKE_SHARED_DEFINITIONS
macro here to add the static function make_shared
to the AnyExecutable
class.
+1 |
Updates based on William's comments in 541385a: use RCLCPP_MAKE_SHARED for shared pointer typedefs for new classes |
@@ -91,7 +98,7 @@ class Executor | |||
{ | |||
this->add_node(node); | |||
// non-blocking = true | |||
std::shared_ptr<AnyExecutable> any_exec = get_next_executable(nonblocking); | |||
AnyExecutable::SharedPtr any_exec = get_next_executable(nonblocking); |
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.
This could use auto
.
Thanks @jacquelinekay, 541385a lgtm. |
size_t _pool_seq; | ||
size_t _exec_seq; | ||
|
||
std::unordered_map<void *, size_t> _memory_map; |
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.
All those member variables should have a trailing underscore and no leading underscore.
|
||
void ** borrow_handles(HandleType type, size_t number_of_handles) | ||
{ | ||
switch (type) { |
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.
Should the code check that number_of_handles
is within the preallocated limits?
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.
yes, definitely. Done in e751530.
LGTM. |
@tfoote Let me know if you're planning to take a look at this PR, otherwise I will merge it soon (next few days). |
+1 |
return std::malloc(size); | ||
} | ||
|
||
virtual void free(void * ptr) |
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.
I'd suggest to name this dealloc, just to mirror alloc.
+1 |
Add "MemoryStrategy" to Executor with dep. injection
…events Remove use_previous_event
use CTest BUILD_TESTING
* ros2GH-112 Open storage for reading handing in rmw_identifier * ros2GH-113 Cleanup: better naming * ros2GH-113 Introduce interface for StorageFactory to allow mocks in tests * ros2GH-113 Add test for SequentialReader for using converters - Added mocks for storage and converters (and factories) * ros2GH-113 Implement skeleton convert function - Use convert only if necessary (different input and output formats), converters are only loaded if really necessary. - Allocate_ros2_message is public to enable extensive tests for this function. - Helper function to get any typesupport by name - Helper function for empty ros2_message * ros2GH-113 Implement allocate_ros2_message - Treats most messages already. - Some combinations of nested messages with arrays are still missing - Cleanup of DynamicArrayNested messages is failing - Main difficulty is the cleanup of the allocated ros2_message which needs to be done manually - The test_ros2_message is intended to be run with valgrind and there should be no leaks or problems with free! * ros2GH-113 Fix DynamicArrayNested deallocation Swapping with empty container seems more stable than deleting the data pointer of the container. * ros2GH-113 Add test for BoundedArrayNested deallocation * ros2GH-113 Refactoring of deallocation code * ros2GH-113 Fix string initialization in all types * ros2GH-113 Fix vector<bool> initialization * ros2GH-113 Add test for deallocation of topic name + Refactoring * ros2GH-113 Minor refactoring of converter * ros2GH-113 Make sure to throw an error if converters do not exist * ros2GH-113 Delete superfluous imports * ros2GH-113 Small fix for deleting vectors * ros2GH-113 Fix build after rebase * ros2GH-30 Minor refactoring - The TODO comments have been removed because they're no longer relevant: they have been discussed in the PR review * ros2GH-30 Give an allocator as parameter to allocate_ros2_message() * ros2GH-111 Add missing test dependencies for CDR converter test * ros2GH-128 Extend message allocation test to also cover big strings - Big strings are not treated with small string optimization and need to be checked, too. * ros2GH-128 Add tests for nested arrays * ros2GH-128 always initialize vectors with a placement new * pass by ref * use new getter functions * consistent function naming * uncrustify * ros2GH-30 Fix windows build * use visibility macros on all functions
This pull request introduces the
MemoryStrategy
class to delegate memory management on the execution path ofExecutor
.By default,
MemoryStrategy
is stateless and handles all delegated functions with dynamic memory management (malloc, free, new), but all functions are overrideable. An example subclass ofMemoryStrategy
,StaticMemoryStrategy
, shows how these functions can be overridden and state can be added to implement fully static memory management.The following functions are delegated to
MemoryStrategy
:borrow_handles
: returns a pointer to memory reserved for subscription, service, client or guard condition handles.return_handles
: cleans up memory instantiated inborrow_handles
, by deleting it or resetting to NULL.instantiate_next_executable
: instantiates the nextAnyExecutable
object and passes it as a shared pointer.In order to manage circular dependencies, I moved the
AnyExecutable
struct from a protected member ofExecutor
to its own header file.An example of how the memory strategy can be specified dynamically is in the
examples/memory_dependency_injection
:https://github.com/ros2/examples/blob/memory_dependency_injection/rclcpp_examples/src/topics/listener_exec.cpp