c# - Converting a mutable Class to immutable Class/Struct -
situation:
i have class looks like:
public class block<c, m> c : icomparable<c> m : imetadata { public block() { lambda = new list<lambda<c, m>>(); } internal int omega { set; get; } internal list<lambda<c, m>> lambda { set; get; } } public class lambda<c, m> c : icomparable<c> m : imetadata { public lambda(char tau, m ati) { this.tau = tau; this.ati = ati; } internal char tau { private set; get; } internal m ati { private set; get; } }
i utilize block
class following:
block<c, m> block = new block<c, m>(); block.lambda.add(new lambda<c, m>(/* parameters */)); block.omega++;
.
question:i store on b+tree +400,000,000 instances of block
; during process lambda
list extended regularly (i.e., multiple block.lambda.add()
).
i'm going multi-thread, hence have alter mutable block
immutable; in regard:
block
potentially larger 16bytes hence based on msdn changing struct
not recommended. an immutable object object state cannot modified after created; block.lambda.add()
violating property! eric lippert's blog on immutability has awesome classification of different immutable objects; however, still i'm not sure type explains situation best.
i'm aware can implement custom add
returns new re-create of block
modified lambda
, although i'm not sure whether thought or not!
at point, i'm stuck @ best solution converting mutable class immutable given big item count. sincerely appreciate suggestion.
c# immutability mutable
No comments:
Post a Comment