c++ - 在 Windows 上找不到 valloc 标识符

标签 c++ windows malloc identifier

我必须修改 Mac 代码以使其在 Windows 上运行,或者至少现在可以编译,但 valloc 似乎有问题。

它说:error C3861: 'valloc': identifier not found.

这是它的用法:

#ifndef _XOPEN_SOURCE_EXTENDED 1
#define _XOPEN_SOURCE_EXTENDED 1
#endif
#include <stdlib.h>

#include <queue>
#include "ArrayArithmetic.h"
#include "MessageObject.h"

#if __SSE__
// allocate memory aligned to 16-bytes memory boundary
#define ALLOC_ALIGNED_BUFFER(_numBytes) (float *) _mm_malloc(_numBytes, 16)
#define FREE_ALIGNED_BUFFER(_buffer) _mm_free(_buffer)
#else
// NOTE(mhroth): valloc seems to work well, but is deprecated!
#define ALLOC_ALIGNED_BUFFER(_numBytes) (float *) valloc(_numBytes)
#define FREE_ALIGNED_BUFFER(_buffer) free(_buffer)
#endif

我有很好的包含,或者至少我是这样认为的。 不,我真的不知道它来自哪里,valloc 在 Windows 上可用吗?

我在 Windows 8.1 和 Visual Studio 2010 上工作。

最佳答案

如果检测到 Windows,请使用 _aligned_malloc/_aligned_free功能。

#ifdef _WIN32

#define ALLOC_ALIGNED_BUFFER(_numBytes) ((float *)_aligned_malloc (_numBytes, 16))
#define FREE_ALIGNED_BUFFER(_buffer) _aligned_free(_buffer)

#elif __SSE__
// allocate memory aligned to 16-bytes memory boundary
#define ALLOC_ALIGNED_BUFFER(_numBytes) (float *) _mm_malloc(_numBytes, 16)
#define FREE_ALIGNED_BUFFER(_buffer) _mm_free(_buffer)
#else
// NOTE(mhroth): valloc seems to work well, but is deprecated!
#define ALLOC_ALIGNED_BUFFER(_numBytes) (float *) valloc(_numBytes)
#define FREE_ALIGNED_BUFFER(_buffer) free(_buffer)
#endif

关于c++ - 在 Windows 上找不到 valloc 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26677401/

相关文章:

c# - 删除 WCFTestClient 的缓存 - 适用于 Visual Studio 2010

c++ - C++ 中的动态内存分配是什么?

c++ - 使用最终类说明符时,最终函数说明符是否多余?

c++ - #include 指令 : relative to where?

c++ - Fork 程序在一段时间后给出 <defunct> 进程

windows - 运行neofetch后powershell立即关闭(Windows终端)

c++ - 如何一步获得商和余数?

Java 音频流平台独立

在 C 中创建一个带有基本路径 + 扩展名和当前日期的文件名 [char *array]

c - 这个使用字符串、malloc 和 strcat 的简单代码有什么问题?