Skip to content

Commit

Permalink
Added MaxProfileSize to the ResourceLimits.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Apr 25, 2024
1 parent 3ed7a34 commit 7451e55
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Magick.NET.Core/IResourceLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public interface IResourceLimits
/// </summary>
ulong MaxMemoryRequest { get; set; }

/// <summary>
/// Gets or sets the max size of a profile in bytes that can be added to the image.
/// </summary>
ulong MaxProfileSize { get; set; }

/// <summary>
/// Gets or sets the pixel cache limit in bytes. Once this memory limit is exceeded, all subsequent pixels cache
/// operations are to/from disk. The default value of this is 50% of the available memory on the machine in 64-bit mode.
Expand Down
5 changes: 5 additions & 0 deletions src/Magick.NET/Native/ResourceLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ private partial class NativeResourceLimits
[Throws]
public static partial void MaxMemoryRequest_Set(ulong value);

public static partial ulong MaxProfileSize_Get();

[Throws]
public static partial void MaxProfileSize_Set(ulong value);

public static partial ulong Memory_Get();

public static partial void Memory_Set(ulong value);
Expand Down
18 changes: 18 additions & 0 deletions src/Magick.NET/ResourceLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public static ulong MaxMemoryRequest
set => NativeResourceLimits.MaxMemoryRequest_Set(value);
}

/// <summary>
/// Gets or sets the max size of a profile in bytes that can be added to the image.
/// </summary>
public static ulong MaxProfileSize
{
get => NativeResourceLimits.MaxProfileSize_Get();
set => NativeResourceLimits.MaxProfileSize_Set(value);
}

/// <summary>
/// Gets or sets the pixel cache limit in bytes. Once this memory limit is exceeded, all subsequent pixels cache
/// operations are to/from disk. The default value of this is 50% of the available memory on the machine in 64-bit mode.
Expand Down Expand Up @@ -151,6 +160,15 @@ ulong IResourceLimits.MaxMemoryRequest
set => MaxMemoryRequest = value;
}

/// <summary>
/// Gets or sets the max size of a profile in bytes that can be added to the image.
/// </summary>
ulong IResourceLimits.MaxProfileSize
{
get => MaxProfileSize;
set => MaxProfileSize = value;
}

/// <summary>
/// Gets or sets the pixel cache limit in bytes. Once this memory limit is exceeded, all subsequent pixels cache
/// operations are to/from disk. The default value of this is 50% of the available memory on the machine in 64-bit mode.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using ImageMagick;
using Xunit;

namespace Magick.NET.Tests;

public partial class ResourceLimitsTests
{
[Collection(nameof(RunTestsSeparately))]
public class TheMaxProfileSizePropertry
{
[Fact]
public void ShouldHaveTheCorrectValue()
{
Assert.Equal((ulong)long.MaxValue, ResourceLimits.MaxProfileSize);
}

[Fact]
public void ShouldReturnTheCorrectValueWhenChanged()
{
var maxProfileSize = ResourceLimits.MaxProfileSize;

ResourceLimits.MaxProfileSize = 42U;
Assert.Equal(42U, ResourceLimits.MaxProfileSize);
ResourceLimits.MaxProfileSize = maxProfileSize;
}
}
}

0 comments on commit 7451e55

Please sign in to comment.