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 7697983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:08:14+00:00 2026-05-31T22:08:14+00:00

I have a program which needs to hold approximately 3000 open file descriptors in

  • 0

I have a program which needs to hold approximately 3000 open file descriptors in Matlab.
The reason for this is that if I dont keep them open I need to open and close them
over 100 000 times which means 300 million open close operations. Considering that each file is appended to each time and fopen and fclose can take upwards of a second each (files are large i.e. 100mb+) it should be clear this situation is unacceptable.

I know that the Windows limit for file handles is set at 10000 but Matlab refuses to open more than 512 files with fopen. I cant figure out how to force it to increase that number.

Does someone know how to change the 512 limit? Where is it defined?
Is it even Matlab related?

  • 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-31T22:08:15+00:00Added an answer on May 31, 2026 at 10:08 pm

    Can’t you really review your program and structure it differently so as to work only from partial memory representation of the files content?

    For instance, if this is to append 100 000 lines to 3000 files (i.e even no need to have any representation of what’s already in the files), you may do it in this way:

    %% Main processing
    function [] FullProcess()
    %[        
        for block = 1:100,
    
            % Partial processing 
            lines = processBlock(block);
    
            % Save step   
            pushToFiles(block, lines);     
    
        end        
    %]
    

    With:

    % Partial processing in memory
    function [lines] = processBlock(block)
    %[
        % Preallocate
        lines = cells(1000, 3000);
    
        % Do the processing for current block
        ...
        lines{500, 12} = 'kikou';
        ...
    %]
    

    And:

    %% Save partial work
    function [] = pushToFiles(block, lines)
    %[
        fcount = size(lines, 2);
        lcount = size(lines, 1);
        for fi = 1:fcount,
    
           [fid, msg] = fopen(fprintf('f%i', fi), 'a'); % Open in append mode
           if (fid < 0), error(msg); end
    
           for li = 1:lcount,
               fprintf(fid, lines{li, fi});
           end
    
           fclose(fid);
    
        end
    %]
    

    This reduce things to do 100 fopen/fclose (by 3000 files though, but this is far less than expected before)

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

Sidebar

Related Questions

I have a Java program which needs to be a startup program that runs
I have a program which needs to behave slightly differently on Tiger than on
I have a program which needs installing on windows 64 boxes. Most of the
I have a program which needs to invoke a process to perform an operation
I have a program which only needs a NotifyIcon to work as intended. So
I have a program which needs to turn many large one-dimensional numpy arrays of
I have a program which needs to upgrade any Access (Jet) database it opens
Simple question here. I have a C# program which needs to stores some files
I have rjecnik.txt file that looks like this mate sime, jure stipica gujo, prvi
I have a program (process) which needs to listen on 3 ports... Two are

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.