linux c/c++ 直接使用底层系统调用效率低

来源:互联网 发布:天猫童装数据 编辑:程序博客网 时间:2024/05/18 23:55

系统调用会影响系统的性能

在执行系统调用时LINUX必须从用户代码切换到内核代码运行

然后在返回到用户代码

开销有点大

#include<unistd.h>//在每个函数中必须最早出现 因为它根据POSIX规范定义的标志可能会影响到其他的文件 要加在前面哦

 

#include<unistd.h>

size_t  write(int fd,const void*buf,size_t nbytes);

size_t read(int fd,void *buf,size_t nbytes);

 

#include<fcntl.h>

#include<sys/types.h>//在某些UNIX上是必不可少的

#include<sys/stat.h>//在某些UNIX上是必不可少的

int open(const char *path,int oflags);

int close(int fd);

 

#include<unistd.h>

int ioctl(int fd,int cmd,...);

 

#include<unistd.h>
#include<sys/types.h>

off_set lseek(int fd,off_t offset,int whence);

 

#include<unistd.h>

#include<sys/stat.h>

#include<sys/types.h>

int  fstat(int fd,struct stat *buf);

int stat(const char *path,struct stat *buf);

int lstat(const char *path,struct stat *buf);

 

 

 

底层调用时一次读写的数据块有限制

标准函数库如I/O库有输出缓冲功能

可以写任意长度的数据块

I/O库函数会在满足数据块长度要求时安排执行底层系统调用

原创粉丝点击