/// <summary> /// This function adds the current record's data to the memory image. /// </summary> public void SaveRecordData() { var memaddress = AddressOffset + Address; // if new address segment starts, save the previous one first if (memaddress != (SegmentEndAddress + 1u)) { FlushSegment(); SegmentStartAddress = memaddress; } MemoryBlocks.Add(Data); SegmentEndAddress = memaddress + (uint)Data.Length - 1u; }
/// <summary> /// Saves the current work segment into the memory image. /// </summary> public void FlushSegment() { if (MemoryBlocks.Count > 0) { // unify the record data blocks into a single segment var memseg = new byte[SegmentEndAddress + 1 - SegmentStartAddress]; uint reladdr = 0; for (int i = 0; i < MemoryBlocks.Count; i++) { MemoryBlocks[i].CopyTo(memseg, reladdr); reladdr += (uint)MemoryBlocks[i].Length; } // add it to the image, and empty the context Memory.TryAddSegment(new Segment(SegmentStartAddress, memseg)); MemoryBlocks.Clear(); } }