/// <summary> /// Find existing field /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <returns>index in the cache or -1(not found)</returns> private int find_field(string name, byte type) { sync_cache(); if (base.ALLOC == ALLOC_TYPE_RAW) { return(-1); // Raw object - return -1 } VSBBTree.BTResult res = FCacheTree.Find(name, 0); int idx = (int)FCacheTree.Find(name, 0).Value; /* * for (int i = 0; i < FCacheIndex.Length; i++) * if (FCacheIndex[i] >= 0) * if (FCache[FCacheIndex[i]].NAME == name) * return FCacheIndex[i]; * * for (int i = 0; i < FCache.Count; i++) * { * if (FCache[i].NAME == name.Trim()) * { * idx = i; * break; * } * } */ if (idx < 0) { return(-1); } if (type > 0) { if (FCache[idx].TYPE != type) { throw new VSException(DEFS.E0026_FIELD_READ_ERROR_CODE, "- " + name + " : type " + FCache[idx].TYPE.ToString() + " doesnt match requested field type " + type.ToString()); } } return(idx); }
/// <summary> /// Return allocated space to the free queue: update FBQE chain and trees /// </summary> /// <param name="address"></param> /// <param name="length"></param> public void ReleaseSpace(long address, long length) { //VSDebug.StopPoint(address, 3740160); CheckFreeQueueSize(); VSBBTree.BTResult res1 = BT_FBQE_Address.Find(address, VSBBTree.COND_LT); VSBBTree.BTResult res2; if (res1.Key < 0) // Update 1st or insert befor 1st - left not found { // Address is before 1st FBQE. Insert new before 1st or extend 1st (new start address) if (this.FIRST < 0) { AddFBQE(address, length, -1, this.FIRST); } else { FBQE f = GetFBQE(this.FIRST); if (f.ADDRESS_START == (address + length)) // Extend 1st FBQE { UpdateFBQE(this.FIRST, address, f.LENGTH + length); } else { AddFBQE(address, length, -1, this.FIRST); // Insert new FBQE at the top of the queue } } } else { res2 = BT_FBQE_Address.Find(address, VSBBTree.COND_GT); if (res2.Key < 0) // Extend last or append { FBQE f = GetFBQE(this.LAST); if (f.ADDRESS_END == address) // Extend last { UpdateFBQE(this.LAST, f.ADDRESS_START, f.LENGTH + length); // Extend } else { AddFBQE(address, length, this.LAST, -1); // Append FBQE } } else { FBQE f1 = GetFBQE((int)res1.Value); FBQE f2 = GetFBQE((int)res2.Value); if ((address > f1.ADDRESS_END) & ((address + length) < f2.ADDRESS_START)) { this.AddFBQE(address, length, f1.index, f2.index); //insert new between f1 and f2 } else // Otherwise merge with left, right or both { if ((address == f1.ADDRESS_END) & ((address + length) == f2.ADDRESS_START)) { // Merge all UpdateFBQE(f1.index, f1.ADDRESS_START, f1.LENGTH + f2.LENGTH + length); DeleteFBQE(f2.index); } else if (address == f1.ADDRESS_END) { // Merge with left (f1) UpdateFBQE(f1.index, f1.ADDRESS_START, f1.LENGTH + length); // Extend f1 (append) } else { // Merge with right (f2) UpdateFBQE(f2.index, address, f2.LENGTH + length); // Extend f2 (insert) } } } } //Clear memory byte[] b = new byte[length]; vm.Write(address, b, length); }