LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   MMAP and pointer (https://www.linuxquestions.org/questions/programming-9/mmap-and-pointer-430440/)

level3 03-31-2006 04:24 PM

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? :scratch: I can not understand it.


Thanks in advance.

dopehouse 03-31-2006 04:38 PM

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.

dopehouse 03-31-2006 04:42 PM

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)

level3 04-02-2006 01:48 PM

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.


All times are GMT -5. The time now is 01:39 AM.