Skip to content

Commit

Permalink
Added missing code comments. Existing code comments updated to use <p…
Browse files Browse the repository at this point in the history
…ara> element for splitting different language versions. Added <inheritdoc> for DocFX. Address arguments renamed to path. Removed comments for exceptions in interfaces.
  • Loading branch information
Konard committed Aug 14, 2019
1 parent 3ed05fe commit 4db4222
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 67 deletions.
15 changes: 12 additions & 3 deletions ArrayMemory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace Platform.Memory
{
/// <summary>
/// Represents a memory block with access via indexer.
/// Представляет блок памяти с доступом через индексатор.
/// <para>Represents a memory block with access via indexer.</para>
/// <para>Представляет блок памяти с доступом через индексатор.</para>
/// </summary>
/// <typeparam name="TElement">Element type. Тип элемента.</typeparam>
/// <typeparam name="TElement"><para>Element type.</para><para>Тип элемента.</para></typeparam>
public class ArrayMemory<TElement> : IArrayMemory<TElement>
{
#region Fields
Expand All @@ -15,8 +15,12 @@ public class ArrayMemory<TElement> : IArrayMemory<TElement>

#region Properties

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="P:Platform.Memory.IMemory.Size"]/*'/>
public long Size => _array.Length;

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="P:Platform.Memory.IArrayMemory`1.Item(System.Int64)"]/*'/>
public TElement this[long index]
{
get => _array[index];
Expand All @@ -27,6 +31,11 @@ public TElement this[long index]

#region Constuctors

/// <summary>
/// <para>Initializes a new instance of the <see cref="ArrayMemory{TElement}"/> class.</para>
/// <para>Инициализирует новый экземпляр класса <see cref="ArrayMemory{TElement}"/>.</para>
/// </summary>
/// <param name="size"><para>Size in bytes.</para><para>Размер в байтах.</para></param>
public ArrayMemory(long size) => _array = new TElement[size];

#endregion
Expand Down
19 changes: 16 additions & 3 deletions DirectMemoryAsArrayMemoryAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Platform.Memory
{
/// <summary>
/// Represents adapter to a memory block with access via indexer.
/// Представляет адаптер к блоку памяти с доступом через индексатор.
/// <para>Represents adapter to a memory block with access via indexer.</para>
/// <para>Представляет адаптер к блоку памяти с доступом через индексатор.</para>
/// </summary>
/// <typeparam name="TElement">Element type. Тип элемента.</typeparam>
/// <typeparam name="TElement"><para>Element type.</para><para>Тип элемента.</para></typeparam>
public class DirectMemoryAsArrayMemoryAdapter<TElement> : DisposableBase, IArrayMemory<TElement>, IDirectMemory
where TElement : struct
{
Expand All @@ -21,10 +21,16 @@ public class DirectMemoryAsArrayMemoryAdapter<TElement> : DisposableBase, IArray

#region Properties

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="P:Platform.Memory.IMemory.Size"]/*'/>
public long Size => _memory.Size;

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="P:Platform.Memory.IDirectMemory.Pointer"]/*'/>
public IntPtr Pointer => _memory.Pointer;

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="P:Platform.Memory.IArrayMemory`1.Item(System.Int64)"]/*'/>
public TElement this[long index]
{
get => Pointer.GetElement(Structure<TElement>.Size, index).GetValue<TElement>();
Expand All @@ -35,12 +41,18 @@ public TElement this[long index]

#region DisposableBase Properties

/// <inheritdoc/>
protected override string ObjectName => $"Array as memory block at '{Pointer}' address.";

#endregion

#region Constructors

/// <summary>
/// <para>Initializes a new instance of the <see cref="DirectMemoryAsArrayMemoryAdapter{TElement}"/> class.</para>
/// <para>Инициализирует новый экземпляр класса <see cref="DirectMemoryAsArrayMemoryAdapter{TElement}"/>.</para>
/// </summary>
/// <param name="memory"><para>An object implementing <see cref="IDirectMemory"/> interface.</para><para>Объект, реализующий интерфейс <see cref="IDirectMemory"/>.</para></param>
public DirectMemoryAsArrayMemoryAdapter(IDirectMemory memory)
{
Ensure.Always.ArgumentMeetsCriteria(m => (m.Size % Structure<TElement>.Size) == 0, memory, nameof(memory), "Memory is not aligned to element size.");
Expand All @@ -51,6 +63,7 @@ public DirectMemoryAsArrayMemoryAdapter(IDirectMemory memory)

#region DisposableBase Methods

/// <inheritdoc/>
protected override void Dispose(bool manual, bool wasDisposed)
{
if (!wasDisposed)
Expand Down
23 changes: 17 additions & 6 deletions FileArrayMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Platform.Memory
{
/// <summary>
/// Represents a memory block with access via indexer and stored as file on disk.
/// Представляет блок памяти с доступом через индексатор и хранящийся в виде файла на диске.
/// <para>Represents a memory block with access via indexer and stored as file on disk.</para>
/// <para>Представляет блок памяти с доступом через индексатор и хранящийся в виде файла на диске.</para>
/// </summary>
/// <typeparam name="TElement">Element type. Тип элемента.</typeparam>
/// <typeparam name="TElement"><para>Element type.</para><para>Тип элемента.</para></typeparam>
public class FileArrayMemory<TElement> : DisposableBase, IArrayMemory<TElement> //-V3073
where TElement : struct
{
Expand All @@ -22,8 +22,12 @@ public class FileArrayMemory<TElement> : DisposableBase, IArrayMemory<TElement>

#region Properties

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="P:Platform.Memory.IMemory.Size"]/*'/>
public long Size => _file.Length;

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="P:Platform.Memory.IArrayMemory`1.Item(System.Int64)"]/*'/>
public TElement this[long index]
{
get
Expand All @@ -42,22 +46,29 @@ public TElement this[long index]

#region DisposableBase Properties

/// <inheritdoc/>
protected override string ObjectName => $"File stored memory block at '{_address}' path.";

#endregion

#region Contructors

public FileArrayMemory(string address)
/// <summary>
/// <para>Initializes a new instance of the <see cref="FileArrayMemory{TElement}"/> class.</para>
/// <para>Инициализирует новый экземпляр класса <see cref="FileArrayMemory{TElement}"/>.</para>
/// </summary>
/// <param name="path"><para>An path to file.</para><para>Путь к файлу.</para></param>
public FileArrayMemory(string path)
{
_address = address;
_file = File.Open(address, FileMode.OpenOrCreate, FileAccess.ReadWrite);
_address = path;
_file = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
}

#endregion

#region DisposableBase Methods

/// <inheritdoc/>
protected override void Dispose(bool manual, bool wasDisposed)
{
if(!wasDisposed)
Expand Down
44 changes: 32 additions & 12 deletions FileMappedResizableDirectMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
namespace Platform.Memory
{
/// <summary>
/// Represents a memory block stored as a file on disk.
/// Представляет блок памяти, хранящийся в виде файла на диске.
/// <para>Represents a memory block stored as a file on disk.</para>
/// <para>Представляет блок памяти, хранящийся в виде файла на диске.</para>
/// </summary>
public unsafe class FileMappedResizableDirectMemory : ResizableDirectMemoryBase
{
Expand All @@ -19,31 +19,47 @@ public unsafe class FileMappedResizableDirectMemory : ResizableDirectMemoryBase
private MemoryMappedFile _file;
private MemoryMappedViewAccessor _accessor;

protected readonly string Address;
/// <summary>
/// <para>Gets path to memory mapped file.</para>
/// <para>Получает путь к отображенному в памяти файлу.</para>
/// </summary>
protected readonly string Path;

#endregion

#region DisposableBase Properties

protected override string ObjectName => $"File stored memory block at '{Address}' path.";
/// <inheritdoc/>
protected override string ObjectName => $"File stored memory block at '{Path}' path.";

#endregion

#region Constructors

public FileMappedResizableDirectMemory(string address, long minimumReservedCapacity)
/// <summary>
/// <para>Initializes a new instance of the <see cref="FileMappedResizableDirectMemory"/> class.</para>
/// <para>Инициализирует новый экземпляр класса <see cref="FileMappedResizableDirectMemory"/>.</para>
/// </summary>
/// <param name="path"><para>An path to file.</para><para>Путь к файлу.</para></param>
/// <param name="minimumReservedCapacity"><para>Minimum file size in bytes.</para><para>Минимальный размер файла в байтах.</para></param>
public FileMappedResizableDirectMemory(string path, long minimumReservedCapacity)
{
Ensure.Always.ArgumentNotEmptyAndNotWhiteSpace(address, nameof(address));
Ensure.Always.ArgumentNotEmptyAndNotWhiteSpace(path, nameof(path));
if (minimumReservedCapacity < MinimumCapacity)
{
minimumReservedCapacity = MinimumCapacity;
}
Address = address;
var size = FileHelpers.GetSize(Address);
Path = path;
var size = FileHelpers.GetSize(Path);
ReservedCapacity = size > minimumReservedCapacity ? ((size / minimumReservedCapacity) + 1) * minimumReservedCapacity : minimumReservedCapacity;
UsedCapacity = size;
}

/// <summary>
/// <para>Initializes a new instance of the <see cref="FileMappedResizableDirectMemory"/> class.</para>
/// <para>Инициализирует новый экземпляр класса <see cref="FileMappedResizableDirectMemory"/>.</para>
/// </summary>
/// <param name="address"><para>An path to file.</para><para>Путь к файлу.</para></param>
public FileMappedResizableDirectMemory(string address) : this(address, MinimumCapacity) { }

#endregion
Expand All @@ -56,7 +72,7 @@ private void MapFile(long capacity)
{
return;
}
_file = MemoryMappedFile.CreateFromFile(Address, FileMode.Open, mapName: null, capacity, MemoryMappedFileAccess.ReadWrite);
_file = MemoryMappedFile.CreateFromFile(Path, FileMode.Open, mapName: null, capacity, MemoryMappedFileAccess.ReadWrite);
_accessor = _file.CreateViewAccessor();
byte* pointer = null;
_accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
Expand Down Expand Up @@ -90,18 +106,22 @@ private bool UnmapFile(IntPtr pointer)

#region ResizableDirectMemoryBase Methods

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="M:Platform.Memory.ResizableDirectMemoryBase.OnReservedCapacityChanged(System.Int64,System.Int64)"]/*'/>
protected override void OnReservedCapacityChanged(long oldReservedCapacity, long newReservedCapacity)
{
UnmapFile();
FileHelpers.SetSize(Address, newReservedCapacity);
FileHelpers.SetSize(Path, newReservedCapacity);
MapFile(newReservedCapacity);
}

protected override void DisposePointer(IntPtr pointer, long size)
/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="M:Platform.Memory.ResizableDirectMemoryBase.DisposePointer(System.IntPtr,System.Int64)"]/*'/>
protected override void DisposePointer(IntPtr pointer, long usedCapacity)
{
if (UnmapFile(pointer))
{
FileHelpers.SetSize(Address, size);
FileHelpers.SetSize(Path, usedCapacity);
}
}

Expand Down
20 changes: 17 additions & 3 deletions HeapResizableDirectMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
namespace Platform.Memory
{
/// <summary>
/// Represents a memory block allocated in Heap.
/// Представляет блок памяти, выделенный в "куче".
/// <para>Represents a memory block allocated in Heap.</para>
/// <para>Представляет блок памяти, выделенный в "куче".</para>
/// </summary>
public unsafe class HeapResizableDirectMemory : ResizableDirectMemoryBase
{
#region DisposableBase Properties

/// <inheritdoc/>
protected override string ObjectName => $"Heap stored memory block at {Pointer} address.";

#endregion

#region Constructors

/// <summary>
/// <para>Initializes a new instance of the <see cref="HeapResizableDirectMemory"/> class.</para>
/// <para>Инициализирует новый экземпляр класса <see cref="HeapResizableDirectMemory"/>.</para>
/// </summary>
/// <param name="minimumReservedCapacity"><para>Minimum file size in bytes.</para><para>Минимальный размер файла в байтах.</para></param>
public HeapResizableDirectMemory(long minimumReservedCapacity)
{
if (minimumReservedCapacity < MinimumCapacity)
Expand All @@ -28,14 +34,22 @@ public HeapResizableDirectMemory(long minimumReservedCapacity)
UsedCapacity = 0;
}

/// <summary>
/// <para>Initializes a new instance of the <see cref="HeapResizableDirectMemory"/> class.</para>
/// <para>Инициализирует новый экземпляр класса <see cref="HeapResizableDirectMemory"/>.</para>
/// </summary>
public HeapResizableDirectMemory() : this(MinimumCapacity) { }

#endregion

#region ResizableDirectMemoryBase Methods

protected override void DisposePointer(IntPtr pointer, long size) => Marshal.FreeHGlobal(pointer);
/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="M:Platform.Memory.ResizableDirectMemoryBase.DisposePointer(System.IntPtr,System.Int64)"]/*'/>
protected override void DisposePointer(IntPtr pointer, long usedCapacity) => Marshal.FreeHGlobal(pointer);

/// <inheritdoc/>
/// <include file='bin\Release\netstandard2.0\Platform.Memory.xml' path='doc/members/member[@name="M:Platform.Memory.ResizableDirectMemoryBase.OnReservedCapacityChanged(System.Int64,System.Int64)"]/*'/>
protected override void OnReservedCapacityChanged(long oldReservedCapacity, long newReservedCapacity)
{
if (Pointer == IntPtr.Zero)
Expand Down
12 changes: 6 additions & 6 deletions IArrayMemory.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace Platform.Memory
{
/// <summary>
/// Represents a memory block interface with access via indexer.
/// Представляет интерфейс блока памяти с доступом через индексатор.
/// <para>Represents a memory block interface with access via indexer.</para>
/// <para>Представляет интерфейс блока памяти с доступом через индексатор.</para>
/// </summary>
/// <typeparam name="TElement">Element type. Тип элемента.</typeparam>
/// <typeparam name="TElement"><para>Element type.</para><para>Тип элемента.</para></typeparam>
public interface IArrayMemory<TElement> : IMemory
{
/// <summary>
/// Gets or sets the element at the specified index.
/// Возвращает или устанавливает элемент по указанному индексу.
/// <para>Gets or sets the element at the specified index.</para>
/// <para>Возвращает или устанавливает элемент по указанному индексу.</para>
/// </summary>
/// <param name="index">The index of the element to get or set. Индекс элемента, который нужно получить или установить.</param>
/// <param name="index"><para>The index of the element to get or set.</para><para>Индекс элемента, который нужно получить или установить.</para></param>
TElement this[long index] { get; set; }
}
}
9 changes: 4 additions & 5 deletions IDirectMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace Platform.Memory
{
/// <summary>
/// Represents a memory block interface with direct access (via unmanaged pointers).
/// Представляет интерфейс блока памяти с прямым доступом (через неуправляемые указатели).
/// <para>Represents a memory block interface with direct access (via unmanaged pointers).</para>
/// <para>Представляет интерфейс блока памяти с прямым доступом (через неуправляемые указатели).</para>
/// </summary>
public interface IDirectMemory : IMemory, IDisposable
{
/// <summary>
/// Gets the pointer to the beginning of this memory block.
/// Возвращает указатель на начало блока памяти.
/// <para>Gets the pointer to the beginning of this memory block.</para>
/// <para>Возвращает указатель на начало блока памяти.</para>
/// </summary>
/// <exception cref="ObjectDisposedException">The memory block is disposed. Блок памяти уже высвобожден.</exception>
IntPtr Pointer { get; }
}
}
8 changes: 4 additions & 4 deletions IMemory.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace Platform.Memory
{
/// <summary>
/// Represents a memory block interface with size in bytes.
/// Представляет интерфейс блока памяти с размером в байтах.
/// <para>Represents a memory block interface with size in bytes.</para>
/// <para>Представляет интерфейс блока памяти с размером в байтах.</para>
/// </summary>
public interface IMemory
{
/// <summary>
/// Gets the size in bytes of this memory block.
/// Возвращает размер блока памяти в байтах.
/// <para>Gets the size in bytes of this memory block.</para>
/// <para>Возвращает размер блока памяти в байтах.</para>
/// </summary>
long Size { get; }
}
Expand Down
Loading

0 comments on commit 4db4222

Please sign in to comment.