CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004

    Unhappy fread & system memory

    I'm trying to read a big file (600Mo) by chunks of 1Mo on Linux (Suse 9.1). Like:
    fp = fopen(...,"rb");
    char buffer[1024*1024];
    int read=1;
    while (read > 0) {
    read = fread(buffer,1,1024*1024,fp);

    This works fine but the used memory (shown by top) grows until the system limit!!
    I've removed buffering with setvbuf but still have the same problem.

    Any idea ? Does the system have its own buffer when reading from file ?

  2. #2
    Join Date
    Dec 2001
    Greece, Athens

    Re: fread & system memory

    Well, I am sure that this doesn't happen in Windows. I've made a program that uses fread periodically for hours (the data in the file is updated from another program). The fread is called every second, so in 2 hours I have more than 7000 calls of fread() and each one of them reads 8000 Bytes of data! And, I do not have sth like u described. I suppose that this shouldn't happen in Linux neither. Are you sure you don't have any memory leak elsewhere? Post some more code.
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

  3. #3
    Join Date
    Oct 2004

    Re: fread & system memory

    Thks, I agree on windows there is no problem : I ran my test program on it and it does not require more memory than the 1Mo buffer allocated.

    It seems to be linked to Linux (or Suse ?).
    I've made some test to play video with ffplay or kaffeine and have the same result. When playing a 60 Mo video, the memory decrease from 60 Mo !! I think Linux (or Suse) have some system memory cache when reading from a file ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.