fread & system memory
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: fread & system memory

  1. #1
    Join Date
    Oct 2004
    Posts
    2

    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
    Location
    Greece, Athens
    Posts
    1,015

    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.
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

  3. #3
    Join Date
    Oct 2004
    Posts
    2

    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center