mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
Done Heap API
This commit is contained in:
parent
feeae54226
commit
3436d1bf37
1 changed files with 22 additions and 1 deletions
|
|
@ -5,9 +5,15 @@ using Native = System.UInt32;
|
|||
|
||||
namespace Cosmos.Core.Memory
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Heap class.
|
||||
/// </summary>
|
||||
public static unsafe class Heap
|
||||
{
|
||||
/// <summary>
|
||||
/// Init heap.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">Thrown on fatal error, contact support.</exception>
|
||||
public static void Init()
|
||||
{
|
||||
HeapSmall.Init();
|
||||
|
|
@ -15,6 +21,11 @@ namespace Cosmos.Core.Memory
|
|||
HeapLarge.Init();
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public static byte* Alloc(Native aSize)
|
||||
{
|
||||
if (aSize <= HeapSmall.mMaxItemSize)
|
||||
|
|
@ -33,6 +44,16 @@ namespace Cosmos.Core.Memory
|
|||
|
||||
// Keep as void* and not byte* or other. Reduces typecasting from callers
|
||||
// who may have typed the pointer to their own needs.
|
||||
/// <summary>
|
||||
/// Free a heap item.
|
||||
/// </summary>
|
||||
/// <param name="aPtr">A pointer to the heap item to be freed.</param>
|
||||
/// <exception cref="Exception">Thrown if:
|
||||
/// <list type="bullet">
|
||||
/// <item>Page type is not found.</item>
|
||||
/// <item>Heap item not found in RAT.</item>
|
||||
/// </list>
|
||||
/// </exception>
|
||||
public static void Free(void* aPtr)
|
||||
{
|
||||
//TODO find a better way to remove the double look up here for GetPageType and then again in the
|
||||
|
|
|
|||
Loading…
Reference in a new issue