作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须修改 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/
我必须修改 Mac 代码以使其在 Windows 上运行,或者至少现在可以编译,但 valloc 似乎有问题。 它说:error C3861: 'valloc': identifier not fou
C(和 C++)包括一系列动态内存分配函数,其中大部分函数的名称都很直观,并且易于向对内存有基本了解的程序员解释。 malloc() 只是分配内存,而 calloc() 分配一些内存并立即清除它。还有
我是一名优秀的程序员,十分优秀!