diff --git a/Arch.LowLevel/Jagged/JaggedArray.cs b/Arch.LowLevel/Jagged/JaggedArray.cs index 982d401..a1d2c88 100644 --- a/Arch.LowLevel/Jagged/JaggedArray.cs +++ b/Arch.LowLevel/Jagged/JaggedArray.cs @@ -118,12 +118,12 @@ public class JaggedArray /// /// The size in bytes. /// The total initial capacity, how many items should fit in. - public JaggedArray(int bucketSize, int capacity = 64) + public JaggedArray(int bucketSize, int capacity = 64, bool increaseOne = true) { _bucketSize = MathExtensions.RoundToPowerOfTwo(bucketSize); _bucketSizeMinusOne = _bucketSize - 1; - _bucketArray = new Bucket[capacity/_bucketSize + 1]; - + _bucketArray = new Bucket[capacity / _bucketSize + (increaseOne ? 1 : 0)]; + _filler = default!; // Fill buckets @@ -141,12 +141,12 @@ public JaggedArray(int bucketSize, int capacity = 64) /// The size in bytes. /// The filler value for all slots, basically a custom default-value. /// The total initial capacity, how many items should fit in. - public JaggedArray(int bucketSize, T filler, int capacity = 64) : this(bucketSize, capacity) + public JaggedArray(int bucketSize, T filler, int capacity = 64, bool increaseOne = true) : this(bucketSize, capacity) { _bucketSize = MathExtensions.RoundToPowerOfTwo(bucketSize); _bucketSizeMinusOne = _bucketSize - 1; - _bucketArray = new Bucket[capacity/_bucketSize + 1]; - + _bucketArray = new Bucket[capacity / _bucketSize + (increaseOne ? 1 : 0)]; + _filler = filler; // Fill buckets @@ -163,6 +163,11 @@ public JaggedArray(int bucketSize, T filler, int capacity = 64) : this(bucketSiz /// public int Capacity => _bucketArray.Length * _bucketSize; + /// + /// The bucket size + /// + public int BucketSize => _bucketSize; + /// /// The length, the buckets inside the . /// diff --git a/Arch.Persistence/Binary.cs b/Arch.Persistence/Binary.cs index 1f1996e..f2cee90 100644 --- a/Arch.Persistence/Binary.cs +++ b/Arch.Persistence/Binary.cs @@ -156,6 +156,7 @@ public void Serialize(ref MessagePackWriter writer, JaggedArray value, Messag // Write length/capacity and items writer.WriteInt32(value.Capacity); + writer.WriteInt32(value.BucketSize); for (var index = 0; index < value.Capacity; index++) { var item = value[index]; @@ -166,7 +167,8 @@ public void Serialize(ref MessagePackWriter writer, JaggedArray value, Messag public JaggedArray Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { var capacity = reader.ReadInt32(); - var jaggedArray = new JaggedArray(CpuL1CacheSize / Unsafe.SizeOf(), _filler,capacity); + var bucketSize = reader.ReadInt32(); + var jaggedArray = new JaggedArray(bucketSize, _filler, capacity, false); for (var index = 0; index < capacity; index++) {