© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
38 replies
jotalanusse

Processing files as fast as possible

Hi everyone! I have a question that I’m sure you can help me with. I’m making a library that needs to parse files as fast as possible. The files in question are binary files containing a sort of protobuf but not quite protobuf.

When parsing a file I only go forward through the file one time, and the data is not modified at all.

I want to know what is the fastest way to go through the file.

At the moment I’m using
MemoryStream
MemoryStream
s, but when I want to process a part of what I just read I have to allocate a new
byte[]
byte[]
and copy the data to it, and I think this can be avoided.

99% of the files I handle won't ever exceed 150MB, maybe even 200MB, so memory isn’t a problem. But the fewer memory I need to allocate apart from the file I’m reading the better. The ideal scenario would be for me to only have one copy of the data in memory, and then be able to reference said data by creating read-only slices to process it.

Is this even possible? Is there a performance overhead for using
MemoryStream
MemoryStream
instead of
byte[]
byte[]
?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ How to deserialize as fast as possible?
C#CC# / help
4mo ago
FizzBuzz as short as possible
C#CC# / help
4y ago
✅ Is there a library for processing FBX or GLTF files?
C#CC# / help
3y ago
How to make an expression as short as possible
C#CC# / help
2y ago