internal Block Allocate(Chunk.Location location, MemoryRequirements requirements) { //Allocate in the first chunk that supports this requirement for (int i = 0; i < chunks.Count; i++) { if (chunks[i].MemoryLocation == location && chunks[i].IsSupported(requirements)) { Block?block = chunks[i].TryAllocate(requirements); if (block != null) { return(block.Value); } } } //If non supported the requirements then create a new chunk Chunk newChunk = new Chunk(logicalDevice, hostDevice, location, requirements.MemoryTypeBits); chunks.Add(newChunk); logger?.Log("MemoryPool", $"New chuck allocated, location: {newChunk.MemoryLocation}, type: {newChunk.MemoryTypeIndex}, size: {ByteUtils.ByteToMegabyte(newChunk.TotalSize)} MB"); //Allocate from the new chunk Block?newBlock = newChunk.TryAllocate(requirements); if (newBlock == null) { throw new Exception( $"[{nameof(Pool)}] New chunk could not allocate this requirements, is it insanely big?"); } return(newBlock.Value); }