在Windows上找不到valloc标识符

时间:2014-10-31 14:47:07

标签: 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

我有好的包括,或者至少我是这么认为的。 不,我真的不知道它来自哪里,Windows上有valloc吗?

我使用Visual Studio 2010在Windows 8.1上工作。

1 个答案:

答案 0 :(得分:1)

如果检测到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