Introduce Struct Wrapper (without pooling)
Akeit0 opened this issue · 0 comments
Akeit0 commented
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);
}
}