等效于sys/mman.h的Windows [英] Windows Equivalent for sys/mman.h

查看:2217
本文介绍了等效于sys/mman.h的Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Win64上编译C代码时遇到问题.更具体地说,编译器找不到sys/mman.h标头,据我了解,该标头仅在Unix环境中找到.

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.

我是否可以使用Windows的等同版本来移植代码(第一次尝试)?

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;
}

推荐答案

您应该查看 mman-win32库.但是正如@Mgetz所指出的,一种更简单的方法是查看[VirtualAllocEx][2]函数并尝试修改您的代码.

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.

这篇关于等效于sys/mman.h的Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆