为了达到测试内存紧张的目的,模拟低内存环境
需要在程序申请大块内存,把系统内存消耗掉
但是又不希望被android各种策略清理掉
eatmenmory.cpp
#include <stdio.h>
#include <cstring>
char* pstr[512];
int main(int argc, char** argv)
{
int a=10;
scanf("%ld",&a);
printf("start eatmenmory %d\n",a);
int i = 512;
for(i = 0; i < a; i++)
{
pstr[i] = new char[1*1024*1024];//(char*)malloc(sizeof(char)*1024*1024);
memset(pstr[i], 1, 1*1024*1024);
printf("allocation eatmenmory %d\n",i);
}
printf("end eatmenmory");
for(;;);
return 0;
}
Android.mk 不可以在windows下生产和编写,如果遇到编译不过的问题,请拷贝一个Android.mk来修改就好了
ninja: error: '/eatmemory.cpp', needed by 'out/target/product/C5_01/obj/EXECUTABLES/eatmemory_intermediates/eatmemory.o', missing and no known rule to make