/// <summary> /// Releases storage associated with the store. /// </summary> public void Deallocate() { #if SPAN childIndices.Dispose(); #endif childIndices = null; }
public MCTSNodeStoreContext(MCTSNodeStore store) { NodeStore = store; PriorContext = curContext; // Update statics curStore = store; curNodes = store.Nodes.nodes; curChildren = store.Children.childIndices; curContext = this; }
/// <summary> /// Constructor. /// </summary> /// <param name="parentStore"></param> /// <param name="maxChildren"></param> public MCTSNodeStructChildStorage(MCTSNodeStore parentStore, long maxChildren) { ParentStore = parentStore; #if SPAN MaxChildren = 1 + maxChildren; childIndices = new MemoryBufferOS <MCTSNodeStructChild>(MaxChildren, MCTSParamsFixed.STORAGE_LARGE_PAGES, SharedMemChildrenName, MCTSParamsFixed.STORAGE_USE_EXISTING_SHARED_MEM, MCTSParamsFixed.STORAGE_USE_INCREMENTAL_ALLOC); #else throw new NotImplementedException("Currently only SPAN mode is supported because otherwise GC may relocate nodes violating assumption"); childIndices = new MCTSNodeStructChild[1 + numChildren]; #endif }
public void Dispose() { if (curStore == null) { throw new Exception("Internal error: MCTSNodeStoreContext improperly nested"); } // Update statics if (PriorContext != null) { curStore = PriorContext.NodeStore; curNodes = PriorContext.NodeStore.Nodes.nodes; curChildren = PriorContext.NodeStore.Children.childIndices; } curContext = PriorContext; }
public static MCTSNodeStore Restore(string directory, string id, bool clearSearchInProgressState = true) { // Read in miscellaneous information file string miscInfoFN = Path.Combine(directory, id + FN_POSTFIX_MISC_INFO); MCTSNodeStoreSerializeMiscInfo miscInfo = SysMisc.ReadObj <MCTSNodeStoreSerializeMiscInfo>(miscInfoFN); MCTSNodeStore store = new MCTSNodeStore(miscInfo.NumNodesReserved); store.Nodes.InsureAllocated(miscInfo.NumNodesAllocated); store.RootIndex = miscInfo.RootIndex; store.Nodes.Reset(miscInfo.PriorMoves, true); long numNodes = SysMisc.ReadFileIntoSpan <MCTSNodeStruct>(Path.Combine(directory, id + FN_POSTFIX_NODES), store.Nodes.Span); //store.Nodes.InsureAllocated((int)numNodes); store.Nodes.nextFreeIndex = (int)numNodes; store.Children.InsureAllocated((int)miscInfo.NumChildrenAllocated); long numChildren = SysMisc.ReadFileIntoSpan <MCTSNodeStructChild>(Path.Combine(directory, id + FN_POSTFIX_CHILDREN), store.Children.Span); if (numChildren > int.MaxValue) { throw new NotImplementedException("Implementation restriction: cannot read stores with number of children exceeding int.MaxValue."); } store.Children.nextFreeBlockIndex = (int)numChildren / MCTSNodeStructChildStorage.NUM_CHILDREN_PER_BLOCK; if (clearSearchInProgressState) { // Reset the search state fields MemoryBufferOS <MCTSNodeStruct> nodes = store.Nodes.nodes; for (int i = 1; i < store.Nodes.NumTotalNodes; i++) { nodes[i].ResetSearchInProgressState(); } } return(store); }