我必须修改 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/