forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96217c6
commit 5373d8d
Showing
14 changed files
with
83 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.IO; | ||
using Microsoft.IO; | ||
using Robust.Shared.IoC; | ||
using Robust.Shared.Log; | ||
using Robust.Shared.Utility; | ||
using SixLabors.ImageSharp.Memory; | ||
|
||
namespace Robust.Shared.GameObjects; | ||
|
||
/// <summary> | ||
/// Generic memory manager for engine use. | ||
/// </summary> | ||
internal sealed class RobustMemoryManager | ||
{ | ||
// Let's be real this is a bandaid for pooling bullshit at an engine level and I don't know what | ||
// good memory management looks like for PVS or the RobustSerializer. | ||
|
||
private static readonly RecyclableMemoryStreamManager MemStreamManager = new() | ||
{ | ||
ThrowExceptionOnToArray = true, | ||
}; | ||
|
||
public RobustMemoryManager() | ||
{ | ||
MemStreamManager.StreamDoubleDisposed += (sender, args) => | ||
throw new InvalidMemoryOperationException("Found double disposed stream."); | ||
|
||
MemStreamManager.StreamFinalized += (sender, args) => | ||
throw new InvalidMemoryOperationException("Stream finalized but not disposed indicating a leak"); | ||
|
||
MemStreamManager.StreamOverCapacity += (sender, args) => | ||
throw new InvalidMemoryOperationException("Stream over memory capacity"); | ||
} | ||
|
||
public static MemoryStream GetMemoryStream() | ||
{ | ||
var stream = MemStreamManager.GetStream(); | ||
DebugTools.Assert(stream.Position == 0); | ||
return stream; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters