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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:33:04+00:00 2026-05-15T03:33:04+00:00

I am reading a file that is 10mb in size and which contains some

  • 0

I am reading a file that is 10mb in size and which contains some id’s. I read them into a list in ruby. I am concerned that it might cause memory issues in the future, when the number of id’s in file might increase. Is there a effective way of reading a large file in batches?

Thank you

  • 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-15T03:33:05+00:00Added an answer on May 15, 2026 at 3:33 am

    there’s no universal way.

    1) you can read file by chunks:

    File.open('filename','r') do |f|
      chunk = f.read(2048)
      ...
    end
    

    disadvantage: you can miss a substring if it’d be between chunks, i.e. you look for “SOME_TEXT”, but “SOME_” is a last 5 bytes of 1st 2048-byte chunk, and “TEXT” is a 4 bytes of 2nd chunk

    2) you can read file line-by-line

    File.open('filename','r') do |f|
      line = f.gets
      ...
    end
    

    disadvantage: this way it’d be 2x..5x slower than first method

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

Sidebar

Related Questions

I've written a Ruby script that is reading a file ( File.read() ) that
I am trying to read contents of a file that is some 3KB into
I'm reading in multuple tiny files and outputing them in a single file that
I'm reading a file that contains Romanian words in Python with file.readline(). I've got
I am trying to read in a file that has HTML list items with
I have a function that is reading a file and adding some of the
I'm reading a .csv file that was created in Excel with the first line
I have a log file that I am reading to a string public static
I am reading in data from a file that has three columns. For example
I am reading data from a file that has, unfortunately, two types of character

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.