gpt4 book ai didi

c - mmap 与 mmap64 有什么区别吗?

转载 作者:行者123 更新时间:2023-11-30 14:33:15 26 4
gpt4 key购买 nike

在 64 位机器上,mmapmmap64 之间有什么区别吗?

还有其他的,例如 fstat64fstat

答案:在 64 位 Ubuntu 18 LTS 上,已验证 mmap 和 mmap64 func addr 是否相同。off_t 和 off64_t 是 64 位。

fstat/stat 能够返回 > 2 GiB 文件大小。

代码:

#include <sys/mman.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;

int main(){
cout << sizeof(off_t) << endl;

void* a = (void*)&mmap64;
void * b = (void*)&mmap;
cout << (a ==b) << endl; // same addr

a = (void*)&fstat64;
b = (void*)&fstat;
cout << (a==b) << endl; // diff addr but able to return > 2 GiB size
}

最佳答案

On a 64-bit machine, is there any difference between mmap vs mmap64?

没有。

引入 *64 接口(interface)是为了启用 Large File Support在 32 位系统上。这在 64 位系统上没有区别。

但是,64 位接口(interface)实际上并未直接向用户公开(不是 POSIX 的一部分)。所以你不应该直接使用*64接口(interface)。如果您碰巧在 32 位系统上需要它们,请使用 feature test macros glibc(例如 _FILE_OFFSET_BITS )。

Macro: _FILE_OFFSET_BITS

This macro determines which file system interface shall be used, one replacing the other. Whereas _LARGEFILE64_SOURCE makes the 64 bit interface available as an additional interface, _FILE_OFFSET_BITS allows the 64 bit interface to replace the old interface.

If _FILE_OFFSET_BITS is undefined, or if it is defined to the value 32, nothing changes. The 32 bit interface is used and types like off_t have a size of 32 bits on 32 bit systems.

If the macro is defined to the value 64, the large file interface replaces the old interface. I.e., the functions are not made available under different names (as they are with _LARGEFILE64_SOURCE). Instead the old function names now reference the new functions, e.g., a call to fseeko now indeed calls fseeko64.

This macro should only be selected if the system provides mechanisms for handling large files. On 64 bit systems this macro has no effect since the *64 functions are identical to the normal functions.

This macro was introduced as part of the Large File Support extension (LFS).

关于c - mmap 与 mmap64 有什么区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59453555/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com