using System; using System.Linq; using System.Threading.Tasks; using Native = System.UInt32; 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; /// /// Init HeapMedium instance. /// /// Empty function static public void Init() { } /// /// 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); } /// /// Free block. /// /// A pointer to the block. /// Thrown if page type is not found. static public void Free(void* aPtr) { HeapLarge.Free(aPtr); } } }