我可以为 Linux 下运行的 C++ 程序分配多少内存?在我的测试用例中,使用newormalloc可以分配超过 170Gb 的内存。作为比较,同样的代码在windows中只能分配1.8G然后终止。
我的测试机,一台是使用virtual box的虚拟机,centos7 64位,2Gb内存。主机是win10 64位,内存8Gb。
下面是测试代码,
#include<iostream>
#include <unistd.h>
#define EVERY_ALLOC_MEM 1024 * 1014 // 1Mb
int main(int argc, char *argv[])
{
std::cout << getpid() << ":" << argv[0] << std::endl;
for (size_t i = 0; ; i++)
{
//char* mem = new char[EVERY_ALLOC_MEM];
char* mem = (char*)malloc(EVERY_ALLOC_MEM);
std::cout << "used " << i << "Mb, that is " << i * 1024 << "Kb, and " …Run Code Online (Sandbox Code Playgroud) 我刚开始使用SS2优化图像处理,但对于3通道24位彩色图像却不知情.我的pix数据由BGR BGR BGR ...排列,unsigned char 8-bi,所以如果我想用SSE2/SSE3/SSE4的C/C++指令实现Color2Gray,我该怎么办?是否需要对齐我的像素数据(4/8/16)?我读过文章:http://supercomputingblog.com/windows/image-processing-with-sse/ 但它是ARGB 4通道32位颜色,每次都精确处理4色像素数据.谢谢!
//Assume the original pixel:
unsigned char* pDataColor=(unsigned char*)malloc(src.width*src.height*3);//3
//init pDataColor every pix val
// The dst pixel:
unsigned char* pDataGray=(unsigned char*)malloc(src.width*src.height*1);//1
Run Code Online (Sandbox Code Playgroud)
// RGB->灰色:Y = 0.212671*R + 0.715160*G + 0.072169*B.