Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 406893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:32:28+00:00 2026-05-12T17:32:28+00:00

Is opening a file stream a costly operation I’d like to provide a lazy

  • 0

Is opening a file stream a costly operation

I’d like to provide a lazy loading functionality in a class that reads a structured file.
Every element of the file has a header and a payload.

the idea is to load only the headers from the file and access the payload data only when the
relevent field is accessed

a prototype of the class would look like this in C#

public class OneElement
{
     public Header TheHeader {get; private set;}

     private string _FileName;

     private long _StreamPosition; // this value is initialized when the header is read

     private Payload _ThePayload;


     public Payload ThePayload
     {
         get{
                    if (_ThePayload == null)
                        using (var stream = File.OpenRead(_FileName) )
                        {
                             stream.seek(_StreamPosition,SeekOrigin.Begin); // seek to the relevent position
                             _ThePayload =  ReadPayload(stream); // this method return the paylod read reads from the current position
                        }
                    return _ThePayload;

               }
     }
} 

Will the operation of opening the file and getting the payload be costly especially in a context where the payload will represent audio or video data

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:32:28+00:00Added an answer on May 12, 2026 at 5:32 pm

    If you’re reading audio/video then I’d expect you to be reading rather a lot of data. That would dwarf the cost of just opening the file. Reading large amounts of data from disk is generally a costly operation though.

    On the other hand, if you were just reading a few bytes at a time then repeatedly opening/closing the file wouldn’t be a good idea – it would be better to read large chunks and cache them appropriately.

    Do you have a benchmark for this? How does it perform at the moment? If it’s working okay, do you have any reason to try to think of a more complicated system?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While opening a file in C# using stream reader is the file going to
I'm opening a stream with funopen FILE *fin = funopen(cookie, readfn, NULL, NULL, closefn);
After opening a file created by root in vim , how to change the
I am opening a file which has 100,000 URL's. I need to send an
I'm opening a file and finding the line I need, but then I have
Simple question: I am opening a file in matlab 7.x, and I want to
What I mean by this, is opening a file with a Java code in
Opening an XML file in Internet explorer gives a security warning. IE has a
In Emacs 23.1 I'm opening up a file with conflict markers from a svn
In Emacs 23.1 I'm opening up a file with conflict markers from a svn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.