Re: Out of memory when reading a large file




yusuf wrote:
Hi,

I'm a newbie to matlab. I have to do the following task:

- read a very large file ~300MB which contains 32 bit binary integers.

I would ideally like to read the data in an array and then be able to
work with the array values. What is happening right now is that I try
to read the file (using fopen/fread), but it gives me out of memory
errors.

Since I need to run functions on the whole data set, is there a way to
read the file into an array, or two arrays?

In order to do what you want, you need enough RAM on your computer.
To get all the data into memory at once, requires 512 MB RAM.
To do work while all the data reside in memory, requires 512 MB more.

So unless your computer has at least 1 GB of RAM, you will have to
chop up the data into smaller chunks. Even if you have enough RAM,
you may want to chop the data up anyway, to ease data handling
and reduce cache misses.

Here's one way to do it:

fid = fopen(filename);
[D,M] = fread(fid,[1000,500],'int32');

I am assuming now that the data is a N x 500 matrix, where you
choose to read 1000 rows (2MB) at a time. You can either check
the number of read elements, M, or the End of File flag, feof, to find
out when you have read all data in the file.

Rune

.



Relevant Pages

  • Re: Out of Memory Problem in VB 6.0 Application.
    ... that's a fixed size array. ... > block of memory. ... Just think of it as 2gigs of ram that you have at your disposal. ... matter if that's real ram or swap file it's still 2 gigs available to your ...
    (microsoft.public.vb.general.discussion)
  • Re: Handling large amounts of data
    ... > stereo sound sample stored at 4bytes per sample, ... > array syntax. ... Writing the data to disk and then memory mapping the files ... of RAM, and 40MB is nothing. ...
    (comp.lang.c)
  • Re: Out of Memory Problem in VB 6.0 Application.
    ... I just remembered that dynamic arrays are pointers to SAFEARRAY structure, ... So memory usage is as follows: ... that's a fixed size array. ... > Just think of it as 2gigs of ram that you have at your disposal. ...
    (microsoft.public.vb.general.discussion)
  • Re: memory issues
    ... If you are running out of memory because your array size is coming ... of memory simply because you dont have enough RAM. ... single mmap file. ...
    (comp.soft-sys.matlab)
  • Re: Dual Port RAM Simulation
    ... the array can not be written. ... Both write processes assign to ram, ... station memory than a signal. ... -- port a read ...
    (comp.lang.vhdl)