Код: Выделить всё
// gcc test_demo.cpp -lpthread -o test_demo
#define LEN 1024*1024*10
static const int array[LEN] = { 0 };
static void* test_memory(void *pArg){
const char *pThreadName = "mem_test";
prctl(PR_SET_NAME, (unsigned long)pThreadName, 0, 0, 0);
int count = 0;
for(int i = 0; i < LEN; i +=16){
count = array[i];
}
printf("test thread, get count=%d \n", count);
getchar();
return NULL;
}
int main(){
printf("Welcome to array example:%d\n", getpid());
getchar();
pthread_t memId;
int status = pthread_create(&memId, NULL,test_memory, NULL);
if(status != 0){
printf("create thread failed,error=%d \n",status);
}
pthread_join(memId, NULL);
printf("main thread\n");
getchar();
return 0;
}
static const int array[LEN] = { 0 };< /code>
Информация SMAPS показывает, что PSS и RSS TEST_DEMO увеличивают около 40м < /li>
const int array[LEN] = { 0 };< /code>
Информация SMAPS показывает, что PSS и RSS TEST_DEMO увеличиваются примерно на 40 м, а блок памяти отображается для Libc.SO, тем временем размер блока памяти составляет 2048 КБ, PSS составляет 8KB.int array[LEN] = { 0 };< /code>
Только блок памяти отображается для libc.so, тем временем размер блока памяти составляет 2048 КБ, PSS - это 8 кб. < /li>
< /ol>
Я не понимаю, почему это произошло.>
Подробнее здесь: https://stackoverflow.com/questions/719 ... ray-and-in