This commit is contained in:
Kudzu 2016-06-14 14:11:00 -04:00
parent d1447458af
commit 7ed55bdbea
8 changed files with 75 additions and 21 deletions

View file

@ -45,12 +45,18 @@ inline increases block size, but makes it faster to find metadata and keeps it u
Could have a single pointer to another record elsewhere, but increases complexity and does not provide Could have a single pointer to another record elsewhere, but increases complexity and does not provide
major benefit. major benefit.
-Data (handle pointer points here) -Data (handle pointer points here)
-64 Ref count -32/64 Ptr to first ref
-64 Ptr to first ref using 32 below saves space on small/med objects. slightly increases access time, but access to these fields is not time critical
-Optional - Stacked and single only -32 (64 to align on large) Ref count
-64 Size (always need, cant interpolate even from slotted as may be smaller than slot) -32 (64 for large) Size (always need, cant interpolate even from slotted as may be smaller than slot)
-Always allocate bigger to word align (or page align for large?). Wont bother .NET, it never needs size from heap. -Always allocate bigger to word align (or page align for large?). Wont bother .NET, it never needs size from heap.
-If need actual size - could add 3 and mask lower 2 bits to round up. -If need align - could add 3 and mask lower 2 bits to round up.
-Optional
-32/64 Size allocated - may be bigger and not needed for slotted etc.
-Tiny
If needed can make tiny types too with only ref and ptr, no need for size. But check heap and
see if such small ones are common. Probably not, likely only for boxing etc.
-Small (Tables) -Small (Tables)
Fixed sizes, max size one page. Fixed sizes, max size one page.

View file

@ -52,6 +52,9 @@
</Choose> </Choose>
<ItemGroup> <ItemGroup>
<Compile Include="Heap.cs" /> <Compile Include="Heap.cs" />
<Compile Include="HeapItemLarge.cs" />
<Compile Include="HeapItemMedium.cs" />
<Compile Include="HeapItemSmall.cs" />
<Compile Include="RAT.cs" /> <Compile Include="RAT.cs" />
<Compile Include="UnitTest1.cs" /> <Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -9,23 +9,29 @@ namespace Cosmos.Core.Memory.Test {
unsafe static public class Heap { unsafe static public class Heap {
static public void Init() { static public void Init() {
} }
static public void* New(Native aSize) { static public void* New(Native aSize) {
return null; return null;
} }
static private void* NewBlock(int aSize) { static private void* NewBlock(Native aSize) {
// size is inclusive? final sizse important when we get to vm return NewBlockLarge(aSize);
}
// Block Status - 1 byte of 4 static private void* NewBlockLarge(Native aSize) {
// -Has Data const Native xPrefixWordsLarge = 4;
// -Empty (Can be removed or merged) const Native xPrefixSizeLarge = xPrefixWordsLarge * sizeof(Native);
// Next Block - Pointer to data. 0 if this is current last.
// Data Size - Native - Size of data, not including header. Native xPages = (Native)((aSize + xPrefixSizeLarge) / RAT.PageSize);
// Data var xPtr = (Native*)RAT.Alloc(RAT.PageType.HeapLarge, xPages);
return null;
xPtr[0] = xPages * RAT.PageSize - xPrefixSizeLarge; // Allocated data size
xPtr[1] = aSize; // Actual data size
xPtr[2] = 0; // Ref count
xPtr[3] = 0; // Ptr to first
return xPtr + xPrefixWordsLarge;
} }
} }
} }

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cosmos.Core.Memory.Test {
static public class HeapItemLarge {
}
}

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cosmos.Core.Memory.Test {
static public class HeapItemMedium {
}
}

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cosmos.Core.Memory.Test {
static public class HeapItemSmall {
}
}

View file

@ -9,8 +9,16 @@ namespace Cosmos.Core.Memory.Test {
unsafe static public class RAT { unsafe static public class RAT {
static public class PageType { static public class PageType {
public const byte Empty = 0; public const byte Empty = 0;
public const byte RAT = 1;
// Data Types from 1, special meanings from 255 down. // Data Types from 1, special meanings from 255 down.
public const byte RAT = 1;
public const byte HeapSmall = 2;
public const byte HeapMedium = 3;
public const byte HeapLarge = 4;
// Code
// Stack
// Disk Cache
// Extension of previous page. // Extension of previous page.
public const byte Extension = 255; public const byte Extension = 255;
} }
@ -80,7 +88,7 @@ namespace Cosmos.Core.Memory.Test {
return xResult; return xResult;
} }
static private byte* Alloc(byte aType, Native aCount = 1) { static public byte* Alloc(byte aType, Native aPageCount = 1) {
Native? xPos = null; Native? xPos = null;
// Could combine with an external method or delegate, but will slow things down // Could combine with an external method or delegate, but will slow things down
@ -88,11 +96,11 @@ namespace Cosmos.Core.Memory.Test {
// //
// Alloc single blocks at bottom, larger blocks at top to help reduce fragmentation. // Alloc single blocks at bottom, larger blocks at top to help reduce fragmentation.
Native xCount = 0; Native xCount = 0;
if (aCount == 1) { if (aPageCount == 1) {
for (Native i = 0; i < mPageCount; i++) { for (Native i = 0; i < mPageCount; i++) {
if (mRAT[i] == PageType.Empty) { if (mRAT[i] == PageType.Empty) {
xCount++; xCount++;
if (xCount == aCount) { if (xCount == aPageCount) {
xPos = i - xCount - 1; xPos = i - xCount - 1;
break; break;
} }
@ -104,7 +112,7 @@ namespace Cosmos.Core.Memory.Test {
for (Native i = mPageCount - 1; i >= 0; i--) { for (Native i = mPageCount - 1; i >= 0; i--) {
if (mRAT[i] == PageType.Empty) { if (mRAT[i] == PageType.Empty) {
xCount++; xCount++;
if (xCount == aCount) { if (xCount == aPageCount) {
xPos = i; xPos = i;
break; break;
} }

View file

@ -17,6 +17,7 @@ namespace Cosmos.Core.Memory.Test {
Assert.IsTrue(xRatPages > 0); Assert.IsTrue(xRatPages > 0);
Native xFreePages = RAT.GetPageCount(RAT.PageType.Empty); Native xFreePages = RAT.GetPageCount(RAT.PageType.Empty);
Assert.IsTrue(xFreePages > 0);
} }
} }
} }