Re: Sharing a file through mmap

From: Måns Rullgård (
Date: 05/14/05

Date: Sat, 14 May 2005 19:54:21 +0200

"Peter Nolan" <> writes:

> Hi,
> I am new to mmap on unix....I have written some ETL software and
> introduced memory mapped IO for my win2000+ version..I am now trying to
> introduce memory mapped IO for my unix version.....
> I have written code that will (I hope) load the data I want into memory
> mapped IO...however, when writing the code to gain access to the map I
> have a question....I have the statement below...
> IF ((ptr_MemMapBuffer = (char *) mmap((caddr_t) 0, 0 ,
> // some error and return
> END_

What language is that?

> At this point in this program I do not know the size of the file
> pointed to by fp_MemMapBuffer. In the win2000 equivalent call when you
> ask for the mapping to be made if you specify 0 as a length it will
> allow the program access to the entire file in memory. I've searched
> in the documentation but I cannot see if mmap defaults to allowing
> access to the entire file or if I need to run some function to find the
> size of the entire file before I call mmap.....And if I do, does anyone
> know the function to call against a file pointer opened with the 'open'
> statement to get the size in bytes of the file?


Måns Rullgård

Relevant Pages

  • Re: FAQ 5.29 How can I read in an entire file all at once?
    ... PS> Are you sure you want to read the entire file and store it in memory? ... PS> you mmap the file, you can virtually load the entire file into a string ... entities and are best loaded into a scalar. ... mmap always needs virtual ram allocated ...
  • Re: [PATCH 1/2]: Fix BUG in cancel_dirty_pages on XFS
    ... will see _none_ of the write because the mmap write occurred during ... inode in the buffered I/O *writeback* path, we have to stop pages being ... filesystems in both locking and the way it treats the page cache. ... No, but the data _in memory_ will, and now when the direct read ...
  • Re: mmap failing with EINVAL inside valgrind
    ... POST++ tries to start the debugger... ... Why don't they just let the application load the file where mmap ... Moi, you might be right with the memory range, that's what I ... BTW can you find any REASON for the code to use a fixed map-adress? ...
  • Re: How process size is calculated? Is it always based on the current highest available address in m
    ... But allocations/deallocations with mmaps can eventually lead to non-continuously mmapped memory. ... Before mmap: ... UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND ...
  • Re: How mmap spends memory
    ... I'm actually interested how does mmap() - munmap() works. ... When you mmapyou are assigning a segment of your process's virtual ... memory segment so that it can be used for other purposes. ...