Skip to content

Possible memory allocation optimization at Utils.cs. #62

Description

@guts117

Thank you for this great project.

I see that there is an error string that is being created even when we have RCL_RET_OK at:

string errorString = PtrToString(errorStringPtr);

A small change in a fork of the repo helped me get 0 allocations in ROS2ForUnity dependent code.
It could go upto 0.9 KBs per class per frame which was very high. (Unity Profiler)

The change looks like this:

    internal static string GetRclErrorString(int ret)
    {
      ...
      string errorString = ret > 0 ? PtrToString(errorStringPtr) : String.Empty;
      ...
    }

I haven't looked much inside the codebase but I assume there is some sort of error message stack in the C side that gets
converted to C# string. If I am correct the message needs to be popped otherwise it won't be coherent.
So, this change shouldn't cause any issues? 🤔

Am I correct in my assessment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions