Questions about mmap()

  • Thread starter Unknown Soldier
  • Start date
U

Unknown Soldier

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 with the existing mapped location,
or do you need to remap it from scratch?

2. If I have a file descriptor returned by a call to socket(), can I
used mmap() as an alterantive to read()? Will there be problems
depending on whether the socket is blocking?

Thanks.
 
F

Flash Gordon

Unknown Soldier wrote, On 08/04/08 20:50:
Hello,

I have a couple queries about mmap() that ppl here might be able to help
with.

<snip>

The people over on comp.unix.programmer are more likely to be able to
provide quality help on this since I am guessing you are using the Unix
mmap function. mmap is a system extension rather than being part of the
C language as defined by the C standard.
 
A

Antoninus Twink

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 with the existing mapped location,
or do you need to remap it from scratch?

There's no guarantee that the original mapping is contained in a large
enough space in the process's virtual address space for the new mapping
to fit, so you really need to unmap and the remap the whole thing.

On Linux, there's an mremap function that takes care of this for you
(it's analogous to realloc), but you should be aware that this function
isn't in POSIX, so relying on it will make your program non-portable.
2. If I have a file descriptor returned by a call to socket(), can I
used mmap() as an alterantive to read()? Will there be problems
depending on whether the socket is blocking?

I don't think so - what would that even mean? It doesn't make sense.
 
K

Keith Thompson

Unknown Soldier said:
I have a couple queries about mmap() that ppl here might be able to
help with.
[snip]

Some people here might try, but you'll get better answers in
comp.unix.programmer. The mmap() function is defined by POSIX, not by
the C language standard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top