mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-11 10:41:33 +00:00
heap
This commit is contained in:
parent
baf1928a28
commit
d1ed1caafb
5 changed files with 31 additions and 7 deletions
|
|
@ -8,12 +8,12 @@ using Native = System.UInt32;
|
|||
namespace Cosmos.Core.Memory.Test {
|
||||
|
||||
unsafe static public class Heap {
|
||||
|
||||
|
||||
static public byte* Alloc(Native aSize) {
|
||||
//TODO - Dont use medium if its close to the page size - does'nt make sense to make a medium page
|
||||
// with only enough free space for something that would be small anyway.
|
||||
if (aSize <= RAT.PageSize - HeapMedium.PrefixBytes) {
|
||||
return HeapLarge.Alloc(aSize);
|
||||
if (aSize <= HeapSmall.MaxItemSize) {
|
||||
return HeapSmall.Alloc(aSize);
|
||||
} else if (aSize <= HeapMedium.MaxItemSize) {
|
||||
return HeapMedium.Alloc(aSize);
|
||||
} else {
|
||||
return HeapLarge.Alloc(aSize);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,5 +8,18 @@ using Native = System.UInt32;
|
|||
namespace Cosmos.Core.Memory.Test {
|
||||
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;
|
||||
|
||||
static public byte* Alloc(Native aSize) {
|
||||
return HeapLarge.Alloc(aSize);
|
||||
}
|
||||
|
||||
static public void Free(void* aPtr) {
|
||||
HeapLarge.Free(aPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,19 @@ 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 HeapSmall {
|
||||
public const Native PrefixBytes = 4 * sizeof(Native);
|
||||
public const Native MaxItemSize = 1024 - PrefixBytes;
|
||||
|
||||
static public byte* Alloc(Native aSize) {
|
||||
return HeapLarge.Alloc(aSize);
|
||||
}
|
||||
|
||||
static public void Free(void* aPtr) {
|
||||
HeapLarge.Free(aPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Cosmos.Core.Memory.Test {
|
|||
// Native Intel page size
|
||||
// x86 Page Size: 4k, 2m (PAE only), 4m
|
||||
// x64 Page Size: 4k, 2m
|
||||
static public readonly Native PageSize = 4096;
|
||||
public const Native PageSize = 4096;
|
||||
|
||||
// Start of area usable for heap, and also start of heap.
|
||||
static private byte* mRamStart;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Cosmos.Core.Memory.Test {
|
|||
public class UnitTest1 {
|
||||
[TestMethod]
|
||||
unsafe public void TestMethod1() {
|
||||
var xRAM = new byte[128 * 1024 * 1024];
|
||||
var xRAM = new byte[128 * 1024 * 1024]; // 128 MB
|
||||
xRAM[0] = 1;
|
||||
fixed (byte* xPtr = xRAM) {
|
||||
RAT.Debug = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue