예제 #1
0
        /// <summary>
        /// Creates a new memory page
        /// </summary>
        /// <param name="minSize">The minimum size required by the page</param>
        public MemoryPage CreatePage(int minSize)
        {
            //Align the size of the page to page sizes.
            int size = ((minSize + this.pageSize - 1) / this.pageSize) * this.pageSize;

            //Allocate writable & readable memory
            var memory = WinAPI.VirtualAlloc(
                IntPtr.Zero,
                (uint)size,
                WinAPI.AllocationType.Commit,
                WinAPI.MemoryProtection.ReadWrite);

            var page = new MemoryPage(memory, size);

            this.pages.Add(page);
            return(page);
        }
예제 #2
0
 /// <summary>
 /// Creates a new heap of the given size
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="managedObjectReferences">The managed object references</param>
 /// <param name="size">The size of the heap</param>
 public ManagedHeap(MemoryManager memoryManager, ManagedObjectReferences managedObjectReferences, int size)
 {
     this.managedObjectReferences = managedObjectReferences;
     this.dataPage       = memoryManager.CreatePage(size);
     this.nextAllocation = this.dataPage.Start;
 }
예제 #3
0
 /// <summary>
 /// Adds the given page to the list of pages and makes it the active one
 /// </summary>
 /// <param name="page">The page</param>
 public void AddPage(MemoryPage page)
 {
     this.pages.Add(page);
     this.ActivePage = page;
 }