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

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

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);
点赞