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

Implement support for inline allocated Boxed types #1234

Merged
merged 5 commits into from Oct 13, 2021

Conversation

sdroege
Copy link
Member

@sdroege sdroege commented Oct 9, 2021

Useful for graphene and code reduction in various other places.

See gtk-rs/gtk-rs-core#211

@sdroege
Copy link
Member Author

sdroege commented Oct 9, 2021

See gtk-rs/gtk-rs-core#284 for the code making use of this.

Useful for graphene and code reduction in various other places.

See gtk-rs/gtk-rs-core#211
Previously only AutoBoxed was considered boxed, which caused wrong code
generation for special functions.
Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost forgot: please update gir book! And please also provide explanations on which type should or shouldn't use boxed_inline.

@sdroege
Copy link
Member Author

sdroege commented Oct 11, 2021

I almost forgot: please update gir book! And please also provide explanations on which type should or shouldn't use boxed_inline.

Good idea. I should probably also update the glib::wrapper! docs a bit more.

@sdroege
Copy link
Member Author

sdroege commented Oct 11, 2021

@GuillaumeGomez Can you shortly check the docs? :)


By default the memory is zero-initialized and copying is done via
`std::ptr::copy()`. If the boxed type contains memory that needs to be freed
then these functions must be provided.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading this, I still have no clue what the rule for boxed_inline is. 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's written just one line above:

Some boxed types are passed as out parameters to functions and the caller is required to allocate them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read but I don't understand it... T_T

Can you provide a simple example please? Or just ignore me, maybe I'm the one in fault here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from that you would use it for types where the second sentence is something you want

configured as inline-allocated boxed type, i.e. the memory of is not allocated on the heap but directly as part of the value e.g. on the stack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, that explains exactly the two cases where you would want this :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a simple example please?

  • gtk::TreeIter, which is allocated by the caller, then a pointer to it is passed to function, then the function fills it in.
  • glib::Value, which is allocated by the caller, then a pointer is passed to e.g. g_object_get_property() and the function fills it in.
  • gdk::RGBA, which is allocated by the caller, then a pointer is passed to various functions and they fill it in.
  • All the graphene types, which ... see above :)

For a case where this not required by useful

  • gst_video::VideoTimeCode, which is just a few integers and you really don't want to pay the heap allocations for them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GuillaumeGomez Does that help in any way?

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.

None yet

2 participants