feat: Updates serialization to use MMF (considerable memory savings) (#1841)
### Summary Updates the serialization strategy to use `MemoryMappedFile` instead of thick buffers. This has the benefit of being on-par with the current implementation (based on hardware/OS), however won't incur the double-memory issue. > [!Important] > **Developer Note** > The `BinaryFileWriter` and `BinaryFileReader` has been removed in favor of `MemoryMapFileWriter` and `UnmanagedDataReader`
This commit is contained in:
parent
3b84c8052c
commit
8ec203f387
27 changed files with 1271 additions and 941 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2024 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ISerializable.cs *
|
||||
* *
|
||||
|
|
@ -14,61 +14,18 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public interface ISerializable : IGenericSerializable
|
||||
{
|
||||
// Should be serialized/deserialized with the index so it can be referenced by IGenericReader
|
||||
// Should be serialized/deserialized with the index that way it can be referenced by IGenericReader
|
||||
DateTime Created { get; set; }
|
||||
|
||||
long SavePosition { get; protected internal set; }
|
||||
BufferWriter SaveBuffer { get; protected internal set; }
|
||||
|
||||
Serial Serial { get; }
|
||||
|
||||
void Deserialize(IGenericReader reader);
|
||||
void Serialize(IGenericWriter writer);
|
||||
|
||||
bool Deleted { get; }
|
||||
void Delete();
|
||||
|
||||
public void InitializeSaveBuffer(byte[] buffer, ConcurrentQueue<Type> types)
|
||||
{
|
||||
SaveBuffer = new BufferWriter(buffer, true, types);
|
||||
if (World.DirtyTrackingEnabled)
|
||||
{
|
||||
SavePosition = SaveBuffer.Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
SavePosition = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void IGenericSerializable.Serialize(ConcurrentQueue<Type> types)
|
||||
{
|
||||
SaveBuffer ??= new BufferWriter(true, types);
|
||||
|
||||
// Clean, don't bother serializing
|
||||
if (SavePosition > -1)
|
||||
{
|
||||
SaveBuffer.Seek(SavePosition, SeekOrigin.Begin);
|
||||
return;
|
||||
}
|
||||
|
||||
SaveBuffer.Seek(0, SeekOrigin.Begin);
|
||||
Serialize(SaveBuffer);
|
||||
|
||||
if (World.DirtyTrackingEnabled)
|
||||
{
|
||||
SavePosition = SaveBuffer.Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.MarkDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue