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#?

Martin
  • 39,309
  • 62
  • 192
  • 278
  • possible duplicate of [A C# equivalent of C's fread file i/o](http://stackoverflow.com/questions/1935851/a-c-equivalent-of-cs-fread-file-i-o) – Timwi Aug 21 '10 at 16:30
  • I posted a [question](http://stackoverflow.com/questions/1935851/a-c-equivalent-of-cs-fread-file-i-o) about this a while ago....and its answered... :D – t0mm13b Aug 21 '10 at 15:32
  • try a MemoryMappedFile maybe ? – juFo Sep 09 '20 at 07:22

1 Answers1

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?

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 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? – Martin Aug 21 '10 at 17:48