Skip to content

Change userData type to avoid boxing #80

Open

Description

@cmann1

Currently userData is an object, which means that to store a struct or value type it needs to be boxed.
Perhaps it could be changed to an int, long, or pointer?

Activity

  1. ikpil commented on Jan 18, 2026

    @ikpil
    Owner

    That’s a great point. I’ve created a new branch to implement these changes. I’ll give it a try now.

  2. cmann1 commented on Jan 19, 2026

    @cmann1
    Author

    Looks good, thanks.

  3. ikpil commented on Jan 19, 2026

    @ikpil
    Owner

    I’ve made the changes and merged them. Could you please take a look?

  4. cmann1 commented on Jan 19, 2026

    @cmann1
    Author

    Awesome thanks it works perfectly.

    Perhaps int/uint overloads for convenience since they're commonly used for indexing arrays?

  5. ikpil commented on Feb 8, 2026

    @ikpil
    Owner

    I understand the convenience aspect, especially for array indexing.
    However, I think adding int/uint overloads would increase the API surface without providing much real benefit.

    B2UserData is intentionally modeled around long / ulong to keep the type semantics explicit and consistent.
    Since GetSigned() and GetUnsigned() already exist, consumers can easily cast to int or uint at the call site when needed.

    Adding additional overloads for narrower integer types also opens the door to further type proliferation, which I’d prefer to avoid to keep the API simple and intention-revealing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions