Skip to content

C++: Generate "arg" version of structs #50

Description

@koplyarov

Problem

Consider the following joint struct:

// Something.idl
struct MyStruct
{
    i32 i;
    IObject obj;
    string str;
}

The C++ code, generated for this struct:

// Something_adapters.hpp
struct MyStruct
{
    int32_t i;
    joint::IObject_Ptr obj;
    joint::String str;

    // constructors, operators, ToString method, etc.
};

The generated C++ struct holds strings and intrusive object pointers by value. Both string copying and atomic operations are unnecessary when the struct is passed as a parameter into a C++ method:

class MyComponent
{
    using JointInterfaces = joint::TypeList<IMyInterface>;

    /**
     * MyStruct instance is constructed somewhere in the accessor code for IMyInterface, 
     * copying the str data and incrementing the atomic reference counter of obj.
     * Both operations are unnecessary for this particular method.
     */
    void Func(const MyStruct& s)
    { std::cout << "s.str: " << s.str << std::endl; }
};

What to do

1. Also generate <StructName>_Arg C++ structure that does not own any expensive-to-copy data somewhere around here

// Something_adapters.hpp
struct MyStruct_Arg
{
    int32_t i;
    joint::IObject_Ref obj;
    joint::StringRef str;

    // constructors, operators, ToString method, etc.
};

2. Construct arg struct version for passing to component methods:

  • add ref_type parameter to CppType constructor here
  • remove recursive parameter and check here

JFYI, here's the unmarshaling of the parameters in C++ adapters template

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions