摘要: On program startup, the integer file descriptors associated with the streams stdin, stdout, and stderr are 0, 1, and 2, respectively. The preprocessor symbols STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO are defined with these values in <unistd.h>. (Applying freopen(3) to one of these stream 阅读全文
posted @ 2013-01-12 15:50 GOD_YCA 阅读(814) 评论(0) 推荐(0)
摘要: 每个进程都有自己的虚拟地址空间,我们知道除了堆中的虚拟内存我们可以由程序员灵活分配和释放,其他的区域的虚拟内存都有系统控制,那么还有没有其他方法让程序员去灵活控制虚拟内存呢?linux下的mmap函数就此而来,mmap函数可以为我们在进程的虚拟空间开辟一块新的虚拟内存,你可以将一个文件映射到这块新的虚拟内存,所以操作新的虚拟内存就是操作这个文件,下面我将介绍mmap函数的运用。首先介绍mmap函数的头文件以及函数声明:#include <sys/mman.h>void *mmap(void* start, size_t length, int prot, int flags, in 阅读全文
posted @ 2013-01-12 15:43 GOD_YCA 阅读(2119) 评论(0) 推荐(0)