/// <summary> /// Create a new instanced area, or return one from the free list if /// there was a free instance. /// </summary> /// <param name="TemplateArea">Supplies the template area object id. /// </param> /// <returns>The instanced area, else OBJECT_INVALID.</returns> private uint CreateAreaInstance(uint TemplateArea) { Stack <uint> FreeList; if (InstancedAreaFreeList.TryGetValue(TemplateArea, out FreeList)) { if (FreeList.Count != 0) { return(FreeList.Pop()); } } uint AreaObject = CreateInstancedAreaFromSource(TemplateArea); if (AreaObject == OBJECT_INVALID) { return(OBJECT_INVALID); } // // We've created a new area, so inform the AI subsystem that there // is a new area to add to its representation. // ClearScriptParams(); AddScriptParameterInt(200); // AREA_ON_INSTANCE_CREATE ExecuteScriptEnhanced("ACR_CreatureBehavior", AreaObject, TRUE); return(AreaObject); }
public override AllocState Alloc(string jobName, int size) { if (size > MemRest) { return new AllocState { OutOfMemory = true } } ; if (!this.All(_ => _.Name != jobName)) { return new AllocState { IsJobExist = true } } ; var toAlloc = FreeList.FirstOrDefault(_ => _.Size >= size); if (toAlloc != null) { toAlloc.Name = jobName; MemRest -= toAlloc.Size; return(new AllocState { Success = true }); } return(new AllocState { NoAvailableUnit = true }); }
public AsyncMessageBrokerCore(MessagePipeDiagnosticsInfo diagnotics, MessagePipeOptions options) { this.handlers = new FreeList <IAsyncMessageHandler <TMessage> >(); this.defaultAsyncPublishStrategy = options.DefaultAsyncPublishStrategy; this.handlingSubscribeDisposedPolicy = options.HandlingSubscribeDisposedPolicy; this.diagnotics = diagnotics; }
/// <summary> /// Try to remove an element from the queue. /// </summary> /// <param name="result"> /// If there's a element available, this parameter will be updated to /// that element. /// </param> /// <returns>Whether the dequeueing operation succeeded.</returns> public bool TryDequeue(out T *result) { result = null; AtomicNode *root = AcquireRoot(); var first = (AtomicNode *)root->Next; var dequeued = (first != null); if (dequeued) { result = (T *)first->Payload; root->Next = first->Next; // if the first node was also the last node, we need to mark the last pointer as well if (root->Payload == (long)first) { root->Payload = 0; } } ReleaseRoot(root); if (dequeued) { FreeList.Release(first); } return(dequeued); }
void Update() { var finish_list = PlayingList.Where(a => a.isPlaying == false); if (finish_list.Count() > 0) { foreach (var source in finish_list) { source.Stop(); source.time = 0f; source.enabled = false; source.loop = false; source.clip = null; source.name = "_pool"; source.gameObject.SetActive(false); FreeList.Push(source); } PlayingList.RemoveAll(s => s.isPlaying == false && s.enabled == false); m_NeedToNormalize = true; } if (m_NeedToNormalize) { Normalize(); m_NeedToNormalize = false; } }
public unsafe void Free(void *ptr) { var tmp = new IntPtr(ptr); FreeList.AddLast(tmp); return; }
public TextureCache( GraphicsDevice graphicsDevice, uint initialLayerCount = 8, uint maxTextureLayers = 32) { _entries = new FreeList <CacheEntry>(); _strongHandles = new List <FreeListHandle>(); _maxTextureLayers = maxTextureLayers; _now = FrameStamp.Invalid; _rgbaTexture = new ArrayTexture( graphicsDevice, PixelFormat.R8_G8_B8_A8_UNorm, initialLayerCount ); _r8Texture = new ArrayTexture( graphicsDevice, PixelFormat.R8_UNorm, initialLayerCount ); _uvRectCache = new GpuCache <TextureLocation>( graphicsDevice, TextureLocation.SizeInGpuBlocks, dimension: 256 ); }
public unsafe GpuCache( GraphicsDevice graphicsDevice, uint typeSizeInGpuBlocks, uint dimension = 128) { _gd = graphicsDevice; _blocksPerSlot = MathUtil.NearestPowerOfTwo(typeSizeInGpuBlocks); _slots = new FreeList(); //_usingGL = _gd.BackendType == GraphicsBackend.OpenGL // || _gd.BackendType == GraphicsBackend.OpenGLES; _usingGL = false; _mapMode = _usingGL ? MapMode.Write : MapMode.ReadWrite; _dimension = dimension = MathUtil.NearestPowerOfTwo(dimension); _capacity = dimension * dimension / _blocksPerSlot; var desc = TextureDescription.Texture2D( dimension, dimension, mipLevels: 1, arrayLayers: 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging ); ResourceFactory rf = _gd.ResourceFactory; _stagingTexture = rf.CreateTexture(ref desc); desc.Usage = TextureUsage.Sampled; _sampledTexture = rf.CreateTexture(ref desc); if (_usingGL) { int dataSize = (int)(dimension * dimension * GpuBlockSize); _glHostMemory = Marshal.AllocHGlobal(dataSize); var span = new Span <byte>(_glHostMemory.ToPointer(), dataSize); span.Clear(); } }
///////////////////////////////////// // PUBLIC METHODS ///////////////////////////////////// public unsafe PhysicalHeap(UIntPtr start, UIntPtr limit) { DebugStub.Assert(MemoryManager.IsPageAligned(start)); DebugStub.Assert(MemoryManager.IsPageAligned(limit)); // Note that this wastes a little bit of memory by allocating // table space to describe page-table memory! UIntPtr numPages = MemoryManager.PagesFromBytes(limit - start); UIntPtr bytesForTable = numPages * BytesPerTableEntry; bytesForTable = MemoryManager.PagePad(bytesForTable); UIntPtr pagesForTable = MemoryManager.PagesFromBytes(bytesForTable); pageCount = numPages - pagesForTable; startAddr = start + bytesForTable; heapLimit = limit; pageTable = (ushort *)start; heapLock = new SpinLock(SpinLock.Types.PhysicalHeap); // The entire heap is free to start out with freeList = new FreeList(); // Initialize the page table SetPages(startAddr, pageCount, FreePage); fixed(PhysicalHeap *thisPtr = &this) { freeList.CreateAndInsert(thisPtr, startAddr, pageCount); } CheckConsistency(); }
AtomicNode *Acquire(long payload, long next) { AtomicNode *node = FreeList.Acquire(); Interlocked.Exchange(ref node->Payload, payload); Interlocked.Exchange(ref node->Next, next); return(node); }
public Octree(Vector3 center, Vector3 size, int depth) { maxDepth = depth; freeNode = -1; rootAABB = new Bounds(center, size); nodes = new List <Node>(); elements = new FreeList <T>(); }
void free(CopyRoot root) { if (_freeList == null) { _freeList = new FreeList <SoftReference <CopyRoot> >(2); } _freeList.free(new SoftReference <CopyRoot>(root)); }
protected ComponentSystem() { // Create basic component data. var idc = 0; freeComponents = new FreeList <int>(() => idc++); aliveComponents = new List <int>(); componentToEntityMap = new Dictionary <int, int>(); }
/// <summary> /// Dispose all resources belonging to the queue /// </summary> public void Dispose() { while (TryDequeue(out _)) { } FreeList.Dispose(); Utility.FreeUnsafe(*m_Root); Utility.FreeUnsafe(m_Root); }
public Cache(Int64 lowWaterMark, Int64 highWaterMark, Int64 blockSize) { entries = new Entries(); spillFile = new Dictionary <string, int>(); cacheLowWatermark = lowWaterMark; cacheHighWatermark = highWaterMark; freeList = new FreeList(blockSize); }
} // At least 4 // constructor public BTreeController(Pager pager, FreeList freeList, int maxCell = 4) { this._pager = pager; this._freeList = freeList; if (maxCell < 4) { throw new Exception($"maxCell expected at least 4, actually {maxCell}"); } this.MaxCell = maxCell; }
private void initFreeList() { FreeLoddingTextBlock.Text = "处理中..."; FreeLoddingProgressBar.Value = 0; for (int i = 0; i < kb.Length; i++) { if (kb[i] != "") { JObject obj = JObject.Parse(kb[i]); if (Int32.Parse(obj["status"].ToString()) == 200) { JArray ClassListArray = Utils.ReadJso(kb[i]); for (int j = 0; j < ClassListArray.Count; j++) { ClassList classitem = new ClassList(); classitem.GetAttribute((JObject)ClassListArray[j]); Debug.WriteLine(Array.IndexOf(classitem.Week, week)); if (Array.IndexOf(classitem.Week, week) != -1) { freeclasstime[classitem.Hash_day, classitem.Hash_lesson] = 1; } } } } FreeLoddingProgressBar.Value = FreeLoddingProgressBar.Value + 100.0 / muIdList.Count; Debug.WriteLine(FreeLoddingProgressBar.Value); } FreeLoddingStackPanel.Visibility = Visibility.Collapsed; for (int i = 0; i < 7; i++) { for (int j = 0; j < 6; j++) { if (freeclasstime[i, j] == 0) { FreeList ft = new FreeList(); ft.vis = 1; ft.weekday = i; mFreeList.Add(ft); break; } } for (int j = 0; j < 6; j++) { if (freeclasstime[i, j] == 0) { FreeList fc = new FreeList(); fc.vis = 0; fc.time = j; mFreeList.Add(fc); } } } }
/// <summary> /// Creates a new B-Tree that uses the given node free list. /// </summary> /// <param name="degree"></param> /// <param name="f"></param> public BTree(int degree, FreeList <T> f) { if (degree <= 1) { Environment.FailFast("bad degree"); } Degree = degree; Cow = new CopyOnWriteContext <T> { FreeList = f }; }
public void AddRange(FreeList <T> list, int length) { if (length < 0) { throw new ArgumentOutOfRangeException("length"); } GrowIfNeeded(length); Array.Copy(list._items, 0, _items, _size, length); _size += length; }
public void TakeTest() { var idc = 0; var list = new FreeList <int>(() => idc++); for (var i = 0; i < 10; i++) { Assert.Equal(i, list.Take()); } }
static void TestExpressionDelete() { string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath); FreeList freeList = new FreeList(pager); BTreeController controller = new BTreeController(pager, freeList); BTreeNode root = null; Expression expression = GetAndsExpression(); for (int i = 1; i < 30; i++) { DBRecord record = GetTestRecord_expression(i, "str", (float)3.3); DBRecord key = GetTestKey_expression(i); if (i == 17 || i == 19) { record = GetTestRecord_expression(i, "str", (float)10.5); } else if (i == 20 || i == 23) { record = GetTestRecord_expression(i, "www", (float)1.3); } root = controller.InsertCell(root, key, record); } List <AttributeDeclaration> attributeNames = new List <AttributeDeclaration>(); AttributeDeclaration attribute_1 = new AttributeDeclaration(); attribute_1.AttributeName = "a"; attribute_1.IsUnique = true; attributeNames.Add(attribute_1); AttributeDeclaration attribute_2 = new AttributeDeclaration(); attribute_2.AttributeName = "b"; attribute_2.IsUnique = false; attributeNames.Add(attribute_2); AttributeDeclaration attribute_3 = new AttributeDeclaration(); attribute_3.AttributeName = "c"; attribute_3.IsUnique = false; attributeNames.Add(attribute_3); root = controller.DeleteCells(root, expression, "a", attributeNames); BTreeNodeHelper.VisualizeIntegerTree(pager, root); pager.Close(); }
public EntitySystem() { // Create entity data. var idc = 0; freeEntities = new FreeList <int>(() => idc++); aliveEntities = new HashSet <int>(); entityTags = new Dictionary <int, string>(); entityAnnotations = new Dictionary <int, uint>(); entityChildren = new Dictionary <int, HashSet <int> >(); entityParents = new Dictionary <int, HashSet <int> >(); }
/// <summary> /// Place an instanced area on the internal free list for its /// associated template area. /// </summary> /// <param name="InstancedArea">Supplies the instanced area to place on /// the free list.</param> private void ReleaseInstancedArea(uint InstancedArea) { uint TemplateArea = GetLocalObject(InstancedArea, "ACR_AREA_INSTANCE_PARENT_AREA"); Stack <uint> FreeList; if (!InstancedAreaFreeList.TryGetValue(TemplateArea, out FreeList)) { FreeList = new Stack <uint>(); InstancedAreaFreeList.Add(TemplateArea, FreeList); } FreeList.Push(InstancedArea); }
public void *Allocate(int size) { if (FreeList.Count > 0) { var p = FreeList.First; FreeList.RemoveFirst(); return(p.Value.ToPointer()); } var buffer = Marshal.AllocHGlobal(size); return(buffer.ToPointer()); }
protected FreeList <T> FindAllList(Predicate <T> match) { FreeList <T> results = new FreeList <T>(); for (int i = 0; i < this._size; i++) { if (match(_items[i])) { results.Add(_items[i]); } } return(results); }
public (IDatabaseController, Pager) UseDatabase(string databaseName) { // init string dbPath = $"./{databaseName}.minidb"; Pager pager = new Pager(dbPath, 1024 * 8, 400); FreeList freeList = new FreeList(pager); IIndexManager bTreeController = new BTreeController(pager, freeList, 40); IInterpreter interpreter = new Parsing(); ICatalogManager catalogManager = new Catalog(databaseName); IRecordManager recordManager = new RecordContext(pager, bTreeController); IDatabaseController database = new DatabaseController(interpreter, catalogManager, recordManager); return(database, pager); }
static void TestFreeList() { string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath, 4096, 100); List <MemoryPage> pageList = new List <MemoryPage>(); pageList.Add(pager.GetNewPage()); // page #2 pageList.Add(pager.GetNewPage()); // page #3 pageList.Add(pager.GetNewPage()); // page #4 pageList.Add(pager.GetNewPage()); // page #5 FreeList freeList = new FreeList(pager); // test initialization MemoryPage newPage = null; newPage = freeList.AllocatePage(); // freeList is now empty Assert.Null(newPage); // recycle pages // MemoryPage tempPage = pager.ReadPage(3); freeList.RecyclePage(pageList[2]); // freeList->4 freeList.RecyclePage(pageList[1]); // freeList->3->4 freeList.RecyclePage(pageList[3]); // freeList->5->3->4 // fetch page from free list newPage = freeList.AllocatePage(); // freeList->3->4 Assert.Equal(5, newPage.PageNumber); newPage = freeList.AllocatePage(); // freeList->4 Assert.Equal(3, newPage.PageNumber); // recycle a page freeList.RecyclePage(pageList[3]); // freeList->5->4 // fetch remaining pages newPage = freeList.AllocatePage(); // freeList->4 Assert.Equal(5, newPage.PageNumber); newPage = freeList.AllocatePage(); // freeList->null Assert.Equal(4, newPage.PageNumber); newPage = freeList.AllocatePage(); // freeList->null Assert.Null(newPage); pager.Close(); }
public void StopSound() { foreach (var source in PlayingList) { source.name = "_pool"; source.Stop(); source.time = 0f; source.enabled = false; source.loop = false; source.clip = null; source.gameObject.SetActive(false); FreeList.Push(source); } PlayingList.Clear(); ++InstanceIndex; }
private static void TestInsertRandomRecord(int maxCell) { string dbPath = "./testdbfile.minidb"; File.Delete(dbPath); Pager pager = new Pager(dbPath); FreeList freeList = new FreeList(pager); BTreeController controller = new BTreeController(pager, freeList); RecordContext recordManager = new RecordContext(pager, controller); // create new table CreateStatement createStatement = GetCreateStatement(); int newRoot = recordManager.CreateTable(); // insert BTreeNode node; InsertStatement insertStatement; int key; int newRootAfterInsert = newRoot; int i; for (i = 0; i < maxCell; i++) { (insertStatement, key) = GetInsertStatement(1); AtomValue atomValue = GetAtomValue(key); newRootAfterInsert = recordManager.InsertRecord(insertStatement.Values, atomValue, newRootAfterInsert); Console.WriteLine(key); Debug.Assert(newRoot == newRootAfterInsert); } node = BTreeNodeHelper.GetBTreeNode(pager, newRootAfterInsert); BTreeNodeHelper.VisualizeIntegerTree(pager, node); Console.WriteLine(); for (i = 0; i < maxCell; i++) { (insertStatement, key) = GetInsertStatement(1); AtomValue atomValue = GetAtomValue(key); newRootAfterInsert = recordManager.InsertRecord(insertStatement.Values, atomValue, newRootAfterInsert); Console.WriteLine(key); } node = BTreeNodeHelper.GetBTreeNode(pager, newRootAfterInsert); BTreeNodeHelper.VisualizeIntegerTree(pager, node); pager.Close(); }
public override AllocState Alloc(string jobName, int size) { if (size > MemRest) { return new AllocState { OutOfMemory = true } } ; if (!this.All(_ => _.Name != jobName)) { return new AllocState { IsJobExist = true } } ; MemoryBlock mem = null; if (Mode == Modes.BF) { //对空闲分区按容量进行升序排序,选择首个能容纳进程的分区分配给进程 mem = FreeList.OrderBy(_ => _.Size).FirstOrDefault(_ => _.Size >= size); } else { //从空闲分区中将第一个能容纳进程的分区分配给进程 mem = FreeList.FirstOrDefault(_ => _.Size >= size); } var memIndex = IndexOf(mem); if (memIndex < 0) { return new AllocState { NoAvailableUnit = true } } ; if ((mem.Size -= size) == 0) { Remove(mem); } Insert(memIndex, new MemoryBlock(jobName, size)); MemRest -= size; return(new AllocState { Success = true }); }