SpanWriter now has an argument that allows it to be resizable.
```cs
public SpanWriter(Span<byte> initialBuffer, bool resize = false)
public SpanWriter(int initialCapacity, bool resize = false)
```
If a SpanWriter is set to be resizable, or given an initial capacity instead of a buffer, it must be disposed:
```cs
public static void SomeMethod()
{
using var writer = new SpanWriter(stackalloc byte[512], true);
// stuff
// Automatic Dispose of writer
}
```
This is because the SpanWriter uses `ArrayPool<byte>.Shared` _rented buffers_ to resize. If the writer is not disposed, those buffers will never be reused resulting in a _memory leak_.
It is possible that the SpanWriter will outright ditch the initial buffer if resize is set to true and growing is needed. To check/account for that we can do the following:
```cs
public static void SomeMethod()
{
Span<byte> span = stackalloc byte[512];
using var writer = new SpanWriter(span, true);
// write some stuff that causes the span to grow
span = writer.RawBuffer;
// Do stuff with the span
}
```
Make sure you don't accidentally `Dispose()` the writer or use the `RawBuffer` outside of the `using` block. If you do, bad things will happen! (NullPointerException, or a fresh SpanWriter with no buffer, depending on the situation).
SpanWriter can also now be used with a fixed statement since it has a `PinnableReference()` function.
36 lines
2.4 KiB
XML
36 lines
2.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
|
|
<PropertyGroup>
|
|
<RootNamespace>Server</RootNamespace>
|
|
<AssemblyName>UOContent</AssemblyName>
|
|
<Product>ModernUO Content</Product>
|
|
<PublishDir>..\..\Distribution\Assemblies</PublishDir>
|
|
<OutDir>..\..\Distribution\Assemblies</OutDir>
|
|
</PropertyGroup>
|
|
<Target Name="CleanPub" AfterTargets="Clean">
|
|
<Message Text="Removing distribution assemblies..." />
|
|
<Delete Files="..\..\Distribution\Assemblies\Argon2.Bindings.dll" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\BouncyCastle.Crypto.dll" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\MailKit.dll" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\MimeKit.dll" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\$(AssemblyName).dll" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\$(AssemblyName).deps.json" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\$(AssemblyName).pdb" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\libargon2.dll" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\libargon2.dylib" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\libargon2.so" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\zlib.dll" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\libz.dylib" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\libz.so" ContinueOnError="true" />
|
|
<Delete Files="..\..\Distribution\Assemblies\ZLib.Bindings.dll" ContinueOnError="true" />
|
|
</Target>
|
|
<ItemGroup>
|
|
<ProjectReference Include="..\Server\Server.csproj" Private="false" PrivateAssets="All" IncludeAssets="None">
|
|
<IncludeInPackage>false</IncludeInPackage>
|
|
</ProjectReference>
|
|
<PackageReference Include="MailKit" Version="2.10.0" />
|
|
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.0.0-preview4" />
|
|
<PackageReference Include="Zlib.Bindings" Version="1.4.0" />
|
|
<PackageReference Include="Argon2.Bindings" Version="1.8.0" />
|
|
</ItemGroup>
|
|
</Project>
|