473,382 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

A question about mmap() function

The prototype of mmap() is:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t
offset);

The second argument len is used to tell mmap() how many bytes I want to
map.
My question is: If len that i give to mmap() is larger than the size of
mapping file, and some data are wrote to these exceeding speces, where
are these data to be wrote to?

In Freebsd, this program section below will be executed without core
dump:
fd=open("mem.tmp", O_RDWR | O_CREAT | O_TRUNC | O_SHLOCK, S_IRWXU);
if(fd<0) {
printf("error at open() (errno: %d).\n", errno);
goto quit;
}
write(fd, empty, 8);
ptr=(char *)mmap((void *)NULL, 9, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
if(fd==MAP_FAILED) {
printf("error at mmap() (errno: %d).\n", errno);
goto quit;
}

ptr[0]='a';
ptr[1]='b';
ptr[2]='b';
ptr[3]='a';
ptr[4]='b';
ptr[5]='b';
ptr[6]='b';
ptr[7]='b';
ptr[8]='z';
But, where is 'z' to be wrote to?

Mar 2 '06 #1
2 6217
bite me if you can... wrote:
The prototype of mmap() is:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t

[snip]

This question is off topic here (as mmap() is *not* part of ISO standard
C); it should be asked in...(see response to your next post)

HTH
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 2 '06 #2
"bite me if you can..." <cc*****@gmail.com> writes:
The prototype of mmap() is:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t
offset);

The second argument len is used to tell mmap() how many bytes I want to
map.
My question is: If len that i give to mmap() is larger than the size of
mapping file, and some data are wrote to these exceeding speces, where
are these data to be wrote to?


We don't know. mmap() is not a standard C function. It's defined by
POSIX, so try comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hao Xu | last post by:
Hi everyone! I found that if you want to write to the memory got by mmap(), you have to get the file descriptor for mmap() in O_RDWR mode. If you got the file descriptor in O_WRONLY mode, then...
1
by: Hao Xu | last post by:
Hi everyone! I found that if you want to write to the memory got by mmap(), you have to get the file descriptor for mmap() in O_RDWR mode. If you got the file descriptor in O_WRONLY mode, then...
4
by: Fabiano Sidler | last post by:
Hi folks! I created an mmap object like so: --- snip --- from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE fl = file('/dev/zero','rw') mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS) ---...
9
by: Owen Zhang | last post by:
I have a file loaded into virtual memory space by mmap. I need to search some key word inside the memory opened by mmap. What is the best and efficient way to do?
5
by: Matias Surdi | last post by:
Suppose I've a process P1, which generates itself a lot of data , for example 2Mb. Then, I've a process P2 which must access P1 shared memory and, probably, modify this data. To accomplish this,...
8
by: Unknown Soldier | last post by:
Hello, I have a couple queries about mmap() that ppl here might be able to help with. 1. What's the best way to resize an mmap()d area when you've enlarged the file? Can you call mmap() again...
2
by: Neal Becker | last post by:
On linux, I don't understand why: f = open ('/dev/eos', 'rw') m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE, flags=mmap.MAP_SHARED) gives 'permission denied', but...
1
by: magnus.lycka | last post by:
Does anyone recognize this little Python crasher? I'll file a bug report unless someone notices it as an already documented bug. I found some open mmap bugs, but it wasn't obvious to me that...
0
by: Akira Kitada | last post by:
Hi list, I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed to build some of the modules. """ Failed to find the necessary bits to build these modules: _bsddb ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.