gpt4 book ai didi

objective-c - 如何将文件映射到 OSX 中的虚拟内存管理器?

转载 作者:搜寻专家 更新时间:2023-10-30 19:45:38 25 4
gpt4 key购买 nike

我正在尝试将文件映射到 OS X 的虚拟内存管理器中。我如何使用 Objective C 在 Mac OS X 上执行此操作?

最佳答案

使用映射。例如

FILE* f = fopen(...);

// Map the file into memory.

// Need the file size.
fseek(f, 0, SEEK_END); // seek to end of file
off_t fileSize = ftello(f); // get current file pointer
fseek(f, 0, SEEK_SET); // seek back to beginning of file
mappedSize = fileSize;

mappedAddress = mmap(0, _mappedSize, PROT_READ, MAP_PRIVATE, f->_file, 0);

... use mappedAddress as a pointer to your data

// Finally free up
munmap(_mappedAddress, _mappedSize);
fclose(f);

关于objective-c - 如何将文件映射到 OSX 中的虚拟内存管理器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30032566/

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