LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-31-2006, 04:24 PM   #1
level3
LQ Newbie
 
Registered: Jan 2006
Posts: 13

Rep: Reputation: 0
MMAP and pointer


Hello,

I use mmap at first time with.

source = mmap (NULL, fst1.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, file, 0)) == (void *) -1)

Return pointer c0xb7fb1000.

after this I use:

source2 = mmap (source, fst1.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, file, 0)) == (void *) -1)

Return pointer 0xb7fb0000.

Why source2 != source? I can not understand it.


Thanks in advance.
 
Old 03-31-2006, 04:38 PM   #2
dopehouse
Member
 
Registered: May 2004
Location: Hildesheim(Germany)
Distribution: Debian Etch with Kernel 2.6.x (latest vanila)
Posts: 62

Rep: Reputation: 15
Read the manpage of mmap. On the first page of the manpage:
Quote:
void * mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);

...preferably at address start. This latter address is a hint only, and is usually specified as 0.

Last edited by dopehouse; 03-31-2006 at 04:39 PM.
 
Old 03-31-2006, 04:42 PM   #3
dopehouse
Member
 
Registered: May 2004
Location: Hildesheim(Germany)
Distribution: Debian Etch with Kernel 2.6.x (latest vanila)
Posts: 62

Rep: Reputation: 15
To have both at the same address, you can use the flag MAP_FIXED, but if that fails, nothing will be done. (It's in the manpage too)
 
Old 04-02-2006, 01:48 PM   #4
level3
LQ Newbie
 
Registered: Jan 2006
Posts: 13

Original Poster
Rep: Reputation: 0
Well is true.

The problem is that I can not write to disk a stream I do not know.

char *hello[]={"Hello I think in this kkkkkkkkkkkkkkkkkkkkkkkkkkkkklllllllllllllllllllllllfin"};
Pointer hello is 0xbfc7efac.
pointer to disk 0xb7f81000 of mmap return.
memcpy (0xbfc7efac to 0xb7f81000 30 bytes).
msync(pointer to disk).

Any error of this functions.

But in file I can not view hello 30 bytes.

I do not understand it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pass pointer,, return pointer??? blizunt7 Programming 3 07-23-2005 01:36 PM
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 01:20 PM
using mmap AngryLlama Programming 1 02-09-2005 08:53 AM
hot to set value of pointer to pointer to a structure in C alix123 Programming 2 11-17-2004 06:40 AM
can I use mmap with sockets? kanth Linux - Networking 0 02-28-2004 05:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration