Home › Forums › Discussions › Support › C# Fast I/O
- This topic has 1 reply, 2 voices, and was last updated 1 year, 10 months ago by Vadim Smirnov.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
February 15, 2023 at 12:33 pm #12819
Hi,
Can you provide a C# example on how to use Fast I/O?
Regards.
February 16, 2023 at 5:57 pm #12820Hi,
I apologize, but I don’t have one. However, I don’t believe it would be a significant issue to port the C++ code to C#. I’m not an expert in C# but it can be something like this:
foreach (PFAST_IO_SECTION i in fast_io_section) { if (Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0) != 0) { Interlocked.Exchange(ref i.fast_io_header.read_in_progress_flag, 1); var write_union = Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0); uint current_packets_success = (uint)write_union.union_.split.number_of_packets; // // Copy packets and reset section // Buffer.BlockCopy(i.fast_io_packets, 0, packet_buffer_, (int)(fast_io_packets_success * Marshal.SizeOf<INTERMEDIATE_BUFFER>()), (int)(current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>()); // For the last packet(s) wait the write completion if in progress write_union = Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0); while (write_union.union_.split.write_in_progress_flag != 0) { write_union = Interlocked.CompareExchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0, 0); } // Copy the last packet(s) Buffer.BlockCopy(i.fast_io_packets, (int)(current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), packet_buffer_, (int)(fast_io_packets_success + current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), Marshal.SizeOf<INTERMEDIATE_BUFFER>()); if (current_packets_success < write_union.union_.split.number_of_packets) { current_packets_success = write_union.union_.split.number_of_packets; Buffer.BlockCopy(i.fast_io_packets, (int)(current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), packet_buffer_, (int)(fast_io_packets_success + current_packets_success - 1) * Marshal.SizeOf<INTERMEDIATE_BUFFER>(), Marshal.SizeOf<INTERMEDIATE_BUFFER>()); } Interlocked.Exchange(ref i.fast_io_header.fast_io_write_union.union_.join, 0); Interlocked.Exchange(ref i.fast_io_header.read_in_progress_flag, 0); fast_io_packets_success += current_packets_success; } }
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.