ModernUO/Projects/UOContent/Gumps
Kamron Batman 582e1877b8
feat(core): Makes spanwriter resizable (#376)
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.
2020-12-31 19:57:02 -08:00
..
Go Removes literal variables (#257) 2020-09-18 18:41:26 -07:00
Guilds feat(core): Makes spanwriter resizable (#376) 2020-12-31 19:57:02 -08:00
Props feat(core): Makes spanwriter resizable (#376) 2020-12-31 19:57:02 -08:00
AddDoorGump.cs C# 9 Cleanup (#325) 2020-11-27 00:29:21 -08:00
AdminGump.cs fix(core): Optimizes strings / .NET 5 compatibility changes (#354) 2020-12-20 23:21:55 -08:00
BanDurationGump.cs Updates a bug (#282) 2020-10-21 20:35:09 -07:00
BaseConfirmGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
BaseGridGump.cs C# 9 Cleanup (#325) 2020-11-27 00:29:21 -08:00
BaseImageTileButtonsGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
ClientGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
CommentsGump.cs Cleanup & Fixes for .NET 5 (#309) 2020-11-15 10:03:50 -08:00
ConfirmBreakCrystalGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
ConfirmHeritageGump.cs Fixes dupe exception (#258) 2020-09-19 15:46:07 -07:00
ConfirmHouseResize.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
ConfirmReleaseGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
DawnsMusicBoxGump.cs fix(core): Converts remaining player packets (#374) 2020-12-30 16:09:51 -08:00
HeritageTokenGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
HonorSelf.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
HouseDemolishGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
HouseGump.cs fix(core): Optimizes strings / .NET 5 compatibility changes (#354) 2020-12-20 23:21:55 -08:00
HouseGumpAOS.cs fix(core): Optimizes strings / .NET 5 compatibility changes (#354) 2020-12-20 23:21:55 -08:00
HouseTransferGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
NoticeGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
PetResurrectGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
PlayerVendorGumps.cs C# 9 Cleanup (#325) 2020-11-27 00:29:21 -08:00
PolymorphGump.cs C# 9 Cleanup (#325) 2020-11-27 00:29:21 -08:00
ReclaimVendorGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
ReportMurderer.cs Removes literal variables (#257) 2020-09-18 18:41:26 -07:00
ResurrectGump.cs Removes literal variables (#257) 2020-09-18 18:41:26 -07:00
RewardGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
RunebookGump.cs Removes literal variables (#257) 2020-09-18 18:41:26 -07:00
SetSecureLevelGump.cs Formats UO Content (#201) 2020-08-27 18:30:38 -07:00
SkillsGump.cs C# 9 Cleanup (#325) 2020-11-27 00:29:21 -08:00
TithingGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
ToTAdminGump.cs Cleanup & Fixes for .NET 5 (#309) 2020-11-15 10:03:50 -08:00
VendorInventoryGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
VendorRentalGumps.cs Removes literal variables (#257) 2020-09-18 18:41:26 -07:00
ViewHousesGump.cs Cleanup & Fixes for .NET 5 (#309) 2020-11-15 10:03:50 -08:00
WarningGump.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00
WhoGump.cs fix(core): Optimizes strings / .NET 5 compatibility changes (#354) 2020-12-20 23:21:55 -08:00
YoungGumps.cs Fixes brace style (#248) 2020-09-13 21:49:46 -07:00