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

small(not complete) save leak fix. Fixes #60 #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Arch.LowLevel/Jagged/JaggedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public class JaggedArray<T>
/// </summary>
/// <param name="bucketSize">The <see cref="Bucket{T}"/> size in bytes.</param>
/// <param name="capacity">The total initial capacity, how many items should fit in.</param>
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<T>[capacity/_bucketSize + 1];
_bucketArray = new Bucket<T>[capacity / _bucketSize + (increaseOne ? 1 : 0)];

_filler = default!;

// Fill buckets
Expand All @@ -141,12 +141,12 @@ public JaggedArray(int bucketSize, int capacity = 64)
/// <param name="bucketSize">The <see cref="Bucket{T}"/> size in bytes.</param>
/// <param name="filler">The filler value for all slots, basically a custom default-value.</param>
/// <param name="capacity">The total initial capacity, how many items should fit in.</param>
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<T>[capacity/_bucketSize + 1];
_bucketArray = new Bucket<T>[capacity / _bucketSize + (increaseOne ? 1 : 0)];

_filler = filler;

// Fill buckets
Expand All @@ -163,6 +163,11 @@ public JaggedArray(int bucketSize, T filler, int capacity = 64) : this(bucketSiz
/// </summary>
public int Capacity => _bucketArray.Length * _bucketSize;

/// <summary>
/// The bucket size
/// </summary>
public int BucketSize => _bucketSize;

/// <summary>
/// The length, the buckets inside the <see cref="_bucketArray"/>.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Arch.Persistence/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void Serialize(ref MessagePackWriter writer, JaggedArray<T> 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];
Expand All @@ -166,7 +167,8 @@ public void Serialize(ref MessagePackWriter writer, JaggedArray<T> value, Messag
public JaggedArray<T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
var capacity = reader.ReadInt32();
var jaggedArray = new JaggedArray<T>(CpuL1CacheSize / Unsafe.SizeOf<T>(), _filler,capacity);
var bucketSize = reader.ReadInt32();
var jaggedArray = new JaggedArray<T>(bucketSize, _filler, capacity, false);

for (var index = 0; index < capacity; index++)
{
Expand Down