mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
Done HeapMedium API
This commit is contained in:
parent
7066eac01c
commit
feeae54226
1 changed files with 44 additions and 16 deletions
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// HeapMedium class. Used to alloc and free medium memory blocks on the heap.
|
||||
/// </summary>
|
||||
unsafe static public class HeapMedium
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of prefix bytes for the heap.
|
||||
/// </summary>
|
||||
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.
|
||||
/// <summary>
|
||||
/// Max item size in a page.
|
||||
/// </summary>
|
||||
public const Native MaxItemSize = RAT.PageSize - 1024;
|
||||
|
||||
static public void Init() {
|
||||
}
|
||||
/// <summary>
|
||||
/// Init HeapMedium instance.
|
||||
/// </summary>
|
||||
/// <remarks>Empty function</remarks>
|
||||
static public void Init()
|
||||
{
|
||||
}
|
||||
|
||||
static public byte* Alloc(Native aSize) {
|
||||
return HeapLarge.Alloc(aSize);
|
||||
}
|
||||
/// <summary>
|
||||
/// Alloc memory block, of a given size.
|
||||
/// </summary>
|
||||
/// <param name="aSize">A size of block to alloc, in bytes.</param>
|
||||
/// <returns>Byte pointer to the start of the block.</returns>
|
||||
static public byte* Alloc(Native aSize)
|
||||
{
|
||||
return HeapLarge.Alloc(aSize);
|
||||
}
|
||||
|
||||
static public void Free(void* aPtr) {
|
||||
HeapLarge.Free(aPtr);
|
||||
/// <summary>
|
||||
/// Free block.
|
||||
/// </summary>
|
||||
/// <param name="aPtr">A pointer to the block.</param>
|
||||
/// <exception cref="Exception">Thrown if page type is not found.</exception>
|
||||
static public void Free(void* aPtr)
|
||||
{
|
||||
HeapLarge.Free(aPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue