Windows Equivalent for sys/mman.h

社会主义新天地 提交于 2019-12-11 10:37:27

问题


I'm encountering issues when trying to compile my C code on Win64. More specifically, the compiler cannot find the sys/mman.h header, which I understand is found in Unix environments only.

I already know this is deals with memory allocation.

Is there an equivalent for Windows I can use in order to port the code (first time trying)?

Code in that causes issues:

/* Allocate memory required by processes */
buf = (int*) malloc (sizeof(int));
if (!buf)
{
    perror("Error");
    free (buf);
    return -3;
}

/* Lock down pages mapped to processes */
puts("Locking down processes.");
if(mlockall (MCL_CURRENT | MCL_FUTURE) < 0)
{
    perror("mlockall");
    free (buf);
    return -4;
}

回答1:


You should look at the mman-win32 library. But as @Mgetz pointed out, a more simple way is to look at the [VirtualAllocEx][2] functions and try to adapt your code.



来源:https://stackoverflow.com/questions/29660492/windows-equivalent-for-sys-mman-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!