http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=213
POSIX . , Windows, POSIX.
mmap():
caddr_t mmap(caddress_t map_addr,
size_t length,
int protection,
int flags,
int fd,
off_t offset);
, .
4 , , , int:
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
int fd;
void * pregion;
if (fd= open(argv[1], O_RDONLY) <0)
{
perror("failed on open");
return –1;
}
pregion=mmap(NULL, 4096, PROT_READ,MAP_SHARED,fd,0);
if (pregion==(caddr_t)-1)
{
perror("mmap failed")
return –1;
}
close(fd);
int val= *((int*) pregion);
}
, munmap():
int munmap(caddr_t addr, int length);
addr - . length , ( ). . - :
munmap(pregion, 1024);