Skip to content
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

Return const ref to reduce copies/allocations #332

Closed
wants to merge 1 commit into from
Closed

Return const ref to reduce copies/allocations #332

wants to merge 1 commit into from

Conversation

mjcarroll
Copy link

Found when running memory audits on the rmw implementations: there is a place where a copy is being used when a const ref should suffice, causing some additional allocations and frees:

 malloc  (not expected) 144 -> 0x5603f5f0c050
 malloc  (not expected) 24 -> 0x5603f9bf3d30
 malloc  (not expected) 144 -> 0x5603f8e5f720
 malloc  (not expected) 24 -> 0x5603f8e50180
 malloc  (not expected) 24 -> 0x5603f500ddf0
 malloc  (not expected) 38 -> 0x5603f51b01a0
 malloc  (not expected) 20 -> 0x5603f951bb20
 free    (not expected) 0x5603f951bb20
 free    (not expected) 0x5603f51b01a0
 free    (not expected) 0x5603f500ddf0
 free    (not expected) 0x5603f8e50180
 free    (not expected) 0x5603f8e5f720
 free    (not expected) 0x5603f9bf3d30
 free    (not expected) 0x5603f5f0c050

In https://github.com/eProsima/Fast-RTPS/blob/master/src/cpp/publisher/PublisherImpl.cpp#L128, when the RTPSParticipantAttributes are retrieved, a copy is returned, rather than a reference or const reference.

As far as I could tell, the copy variant of the method wasn't being used anywhere, so switching to the const ref version shouldn't cause issues. If it is being used, then having multiple variations should be suitable.

@wjwwood
Copy link
Contributor

wjwwood commented Nov 19, 2018

@dejanpan FYI

@MiguelCompany
Copy link
Member

MiguelCompany commented Nov 20, 2018

This was already done as part of #254 (commit 22ac8c9) and will be part of the next release (see #304)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants