From feeae542268276d4ff73888c0bcaadbfb86d2e44 Mon Sep 17 00:00:00 2001 From: Elia Sulimanov Date: Wed, 19 Aug 2020 16:00:16 +0300 Subject: [PATCH] Done HeapMedium API --- source/Cosmos.Core/Memory/HeapMedium.cs | 60 ++++++++++++++++++------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/source/Cosmos.Core/Memory/HeapMedium.cs b/source/Cosmos.Core/Memory/HeapMedium.cs index 4ff0e3997..34a153808 100644 --- a/source/Cosmos.Core/Memory/HeapMedium.cs +++ b/source/Cosmos.Core/Memory/HeapMedium.cs @@ -3,24 +3,52 @@ using System.Linq; using System.Threading.Tasks; using Native = System.UInt32; -namespace Cosmos.Core.Memory { - unsafe static public class HeapMedium { - public const Native PrefixBytes = 4 * sizeof(Native); - // TODO Adjust when page size changes from 4k to 2/4mb - // Also adjust according to heap stats and final adjustments to small heap. ie the -1024 should be at least size of - // max small heap else it will never get used; - // HeapMedium may be of limited use with 4k pages depending on the final sizes of the small heap. - public const Native MaxItemSize = RAT.PageSize - 1024; +namespace Cosmos.Core.Memory +{ + /// + /// HeapMedium class. Used to alloc and free medium memory blocks on the heap. + /// + unsafe static public class HeapMedium + { + /// + /// Number of prefix bytes for the heap. + /// + public const Native PrefixBytes = 4 * sizeof(Native); + // TODO Adjust when page size changes from 4k to 2/4mb + // Also adjust according to heap stats and final adjustments to small heap. ie the -1024 should be at least size of + // max small heap else it will never get used; + // HeapMedium may be of limited use with 4k pages depending on the final sizes of the small heap. + /// + /// Max item size in a page. + /// + public const Native MaxItemSize = RAT.PageSize - 1024; - static public void Init() { - } + /// + /// Init HeapMedium instance. + /// + /// Empty function + static public void Init() + { + } - static public byte* Alloc(Native aSize) { - return HeapLarge.Alloc(aSize); - } + /// + /// Alloc memory block, of a given size. + /// + /// A size of block to alloc, in bytes. + /// Byte pointer to the start of the block. + static public byte* Alloc(Native aSize) + { + return HeapLarge.Alloc(aSize); + } - static public void Free(void* aPtr) { - HeapLarge.Free(aPtr); + /// + /// Free block. + /// + /// A pointer to the block. + /// Thrown if page type is not found. + static public void Free(void* aPtr) + { + HeapLarge.Free(aPtr); + } } - } }