在Windows上找不到valloc标识符

问题描述:

我必须修改Mac代码才能使其在Windows上工作,或者至少需要编译,但valloc似乎存在问题。在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

我在Windows 8.1中的工作与Visual Studio 2010

+1

您应该标记语言。我猜C,但你包括''。 – crashmstr 2014-10-31 14:51:13

+0

“'valloc()'函数分配内存的大小字节并返回一个指向已分配内存的指针,分配的内存在页边界上对齐。” [(源)](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/valloc.3.html)。如果页面对齐在这段代码中很重要(谁知道?),你将不得不写一个替代品。 – usr2564301 2014-10-31 14:53:54

+0

..这可能有助于Windows:http://*.com/questions/10862121/undefined-reference-to-posix-memalign-using-mingw32 – usr2564301 2014-10-31 14:55:54

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