1

I need to read/write file which as light as possible and with super-fast read and write access. In other words, I cannot use serialization or binary serialization. I have to be able to update a single records and seek in the file quickly.

Essentially, I need a file structure similar to what I would do in C/C++ (i.e. fixed size structure with a defined size that I can read/write on the file and allow me to seek in it). Any idea how to do that in C#?

3
  • I posted a question about this a while ago....and its answered... :D Commented Aug 21, 2010 at 15:32
  • possible duplicate of A C# equivalent of C's fread file i/o Commented Aug 21, 2010 at 16:30
  • try a MemoryMappedFile maybe ? Commented Sep 9, 2020 at 7:22

1 Answer 1

1

There is no reason you can't just use the FileStream or more generally the Stream class to accomplish this goal. Both of these classes support seeking and reading the raw data from a file without any serialization necessary. Is there a reason this doesn't work for your scenario?

Sign up to request clarification or add additional context in comments.

1 Comment

I have a struct with a couple of int, long, double, and date. I want to be able to open the file and seek at the exact position of the 100th record. Would it be possible with the FileStream? If so, how?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.