Skip to content
Merged
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
5 changes: 5 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@
* `void SetUnixFileMode(string, UnixFileMode)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.setunixfilemode?view=net-11.0#system-io-file-setunixfilemode(system-string-system-io-unixfilemode))


#### GC

* `T[] AllocateUninitializedArray<T>(int, bool)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0)


#### Guid

* `bool TryFormat(Span<byte>, int, ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryformat?view=net-11.0#system-guid-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))))
Expand Down
25 changes: 15 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ This project uses features from the current stable SDK and C# language. As such
| net5.0 | 9.5KB | 208.0KB | +198.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB |
| net6.0 | 10.0KB | 152.0KB | +142.0KB | +10.0KB | +7.0KB | +512bytes | +4.0KB |
| net7.0 | 10.0KB | 117.5KB | +107.5KB | +9.0KB | +5.5KB | +512bytes | +4.0KB |
| net8.0 | 9.5KB | 89.0KB | +79.5KB | +8.5KB | +512bytes | +1.0KB | +3.5KB |
| net8.0 | 9.5KB | 89.0KB | +79.5KB | +9.0KB | +512bytes | +1.0KB | +3.5KB |
| net9.0 | 9.5KB | 47.0KB | +37.5KB | +9.0KB | | +1.0KB | +3.5KB |
| net10.0 | 10.0KB | 23.5KB | +13.5KB | +9.0KB | | +512bytes | +3.5KB |
| net11.0 | 10.0KB | 18.5KB | +8.5KB | +9.0KB | | +512bytes | +3.5KB |
Expand All @@ -124,23 +124,23 @@ This project uses features from the current stable SDK and C# language. As such
| | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability |
|----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------|
| netstandard2.0 | 8.0KB | 436.4KB | +428.4KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| netstandard2.1 | 8.5KB | 363.0KB | +354.5KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB |
| net461 | 8.5KB | 434.4KB | +425.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net462 | 7.0KB | 437.9KB | +430.9KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB |
| netstandard2.1 | 8.5KB | 362.9KB | +354.4KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB |
| net461 | 8.5KB | 434.3KB | +425.8KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net462 | 7.0KB | 437.8KB | +430.8KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB |
| net47 | 7.0KB | 437.6KB | +430.6KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net471 | 8.5KB | 437.6KB | +429.1KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net472 | 8.5KB | 435.0KB | +426.5KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net48 | 8.5KB | 435.0KB | +426.5KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net481 | 8.5KB | 435.0KB | +426.5KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| netcoreapp2.0 | 9.0KB | 402.3KB | +393.3KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB |
| netcoreapp2.1 | 9.0KB | 370.2KB | +361.2KB | +16.7KB | +8.7KB | +14.4KB | +19.4KB |
| netcoreapp2.2 | 9.0KB | 370.2KB | +361.2KB | +16.7KB | +8.7KB | +14.4KB | +19.4KB |
| netcoreapp3.0 | 9.5KB | 351.9KB | +342.4KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB |
| netcoreapp2.1 | 9.0KB | 370.1KB | +361.1KB | +16.7KB | +8.7KB | +14.4KB | +19.4KB |
| netcoreapp2.2 | 9.0KB | 370.1KB | +361.1KB | +16.7KB | +8.7KB | +14.4KB | +19.4KB |
| netcoreapp3.0 | 9.5KB | 351.8KB | +342.3KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB |
| netcoreapp3.1 | 9.5KB | 350.3KB | +340.8KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net5.0 | 9.5KB | 297.2KB | +287.8KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net6.0 | 10.0KB | 223.5KB | +213.5KB | +17.7KB | +8.7KB | +1.1KB | +4.7KB |
| net5.0 | 9.5KB | 297.2KB | +287.7KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB |
| net6.0 | 10.0KB | 223.4KB | +213.4KB | +17.7KB | +8.7KB | +1.1KB | +4.7KB |
| net7.0 | 10.0KB | 170.2KB | +160.2KB | +16.6KB | +6.9KB | +1.1KB | +4.7KB |
| net8.0 | 9.5KB | 126.8KB | +117.3KB | +16.0KB | +811bytes | +1.6KB | +4.2KB |
| net8.0 | 9.5KB | 126.8KB | +117.3KB | +16.5KB | +811bytes | +1.6KB | +4.2KB |
| net9.0 | 9.5KB | 67.8KB | +58.3KB | +16.5KB | | +1.6KB | +4.2KB |
| net10.0 | 10.0KB | 35.8KB | +25.8KB | +16.5KB | | +1.1KB | +4.2KB |
| net11.0 | 10.0KB | 27.4KB | +17.4KB | +16.5KB | | +1.1KB | +4.2KB |
Expand Down Expand Up @@ -901,6 +901,11 @@ The class `Polyfill` includes the following extension methods:
* `void SetUnixFileMode(string, UnixFileMode)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.setunixfilemode?view=net-11.0#system-io-file-setunixfilemode(system-string-system-io-unixfilemode))


#### GC

* `T[] AllocateUninitializedArray<T>(int, bool)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0)


#### Guid

* `bool TryFormat(Span<byte>, int, ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryformat?view=net-11.0#system-guid-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))))
Expand Down
5 changes: 5 additions & 0 deletions src/Consume/Consume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ void Console_Methods()
using var stderr = Console.OpenStandardErrorHandle();
}

void GC_Methods()
{
var array = GC.AllocateUninitializedArray<int>(10);
}

void File_Methods()
{
const string TestFilePath = "testfile.txt";
Expand Down
29 changes: 29 additions & 0 deletions src/Polyfill/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false)
{
if (pinned)
{
throw new NotSupportedException("Pinned allocations are not supported on this runtime.");
}

return new T[length];
}

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net10.0/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net11.0/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net461/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net462/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net47/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net471/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net472/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net48/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net481/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net5.0/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net6.0/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
23 changes: 23 additions & 0 deletions src/Split/net7.0/GCPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NET5_0_OR_GREATER

namespace Polyfills;

using System;
using System.Runtime.CompilerServices;

static partial class Polyfill
{
extension(GC)
{
/// <summary>
/// Allocates an array of a specified type and length. Provides source-level compatibility
/// with newer APIs. On older runtimes the returned array is zero-initialized.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-11.0
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) =>
new T[length];

}
}
#endif
Loading
Loading