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

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

在执行系统调用时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库函数会在满足数据块长度要求时安排执行底层系统调用

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值