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

Introduce Struct Wrapper (without pooling) #71

Open
Akeit0 opened this issue Jan 18, 2024 · 0 comments
Open

Introduce Struct Wrapper (without pooling) #71

Akeit0 opened this issue Jan 18, 2024 · 0 comments

Comments

@Akeit0
Copy link
Contributor

Akeit0 commented Jan 18, 2024

Related to #33
On delegate binding, struct wrapper class will reduce allocation even if it is not pooled.
Because non static lambda allocates an anonymous wrapper and a delegate.
Furthermore, as for int types, you can share the ones you use most often.

public class ReadOnlyIntBox{
    public readonly int Value;
    public ReadOnlyIntBox(int value){
        Value=value;
    }
   static ReadOnlyIntBox[] sharedBoxes=new ReadOnlyIntBox[sharedSize] ;
    const sharedSize=16;
    public static Create(int value){
        if(0<=value&&value<sharedSize){
             ref var shared=ref sharedBoxes[value];
             if(shared==null) shared=new ReadOnlyIntBox(value);
             return shared;
        }
        return new ReadOnlyIntBox(value);
    }
}
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

No branches or pull requests

1 participant