c++之小试牛刀

来源:互联网 发布:ubuntu 新建 文件 权限 编辑:程序博客网 时间:2024/04/30 06:28
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(int argc, char *argv[]){   int nMaxSize = 1*1024*1024;   int nCount = atoi(argv[1]);   printf("ncount = %d\n", nCount);   for (int i = 0; i<nCount; i++)   {      char *s = (char*) malloc(nMaxSize);      if (s == NULL) break;      printf("Malloc %d,size =%d,s=%x\n",i, nMaxSize,s);      strcpy(s,"1000");      s[nMaxSize-1] = 0;      memset(s,0,nMaxSize);   }   while(1)   {      sleep(1);   }   return 0;};


 

原创粉丝点击