mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 12:30:32 +00:00
24 lines
715 B
C#
24 lines
715 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Native = System.UInt32;
|
|
|
|
namespace Cosmos.Core.Memory.Test {
|
|
unsafe static public class HeapLarge {
|
|
public const Native PrefixBytes = 4 * sizeof(Native);
|
|
|
|
static public byte* Alloc(Native aSize) {
|
|
Native xPages = (Native)((aSize + PrefixBytes) / RAT.PageSize) + 1;
|
|
var xPtr = (Native*)RAT.Alloc(RAT.PageType.HeapLarge, xPages);
|
|
|
|
xPtr[0] = xPages * RAT.PageSize - PrefixBytes; // Allocated data size
|
|
xPtr[1] = aSize; // Actual data size
|
|
xPtr[2] = 0; // Ref count
|
|
xPtr[3] = 0; // Ptr to first
|
|
|
|
return (byte*)xPtr + PrefixBytes;
|
|
}
|
|
}
|
|
}
|