我可以做一个写入时复制的memcpy在Linux呢? [英] Can I do a copy-on-write memcpy in Linux?
问题描述
我有一些code,其中我经常复制一个大的内存块,往往只能做很小的改动后。
I have some code where I frequently copy a large block of memory, often after making only very small changes to it.
我已经实现跟踪变化的系统,但我想这可能是很好,如果可能的话,告诉操作系统做一个写入时复制的记忆,让它只处理制作副本的那些变化的部分。不过虽然Linux确实写入时复制,例如当fork()的ING,我无法找到控制它,做它自己的方式。
I have implemented a system which tracks the changes, but I thought it might be nice, if possible to tell the OS to do a 'copy-on-write' of the memory, and let it deal with only making a copy of those parts which change. However while Linux does copy-on-write, for example when fork()ing, I can't find a way of controlling it and doing it myself.
推荐答案
您最好的机会可能是的mmap()
原始数据文件,然后的mmap()
相同的文件再次使用 MAP_PRIVATE
。
Your best chance is probably to mmap()
the original data to file, and then mmap()
the same file again using MAP_PRIVATE
.
这篇关于我可以做一个写入时复制的memcpy在Linux呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!