test_demo.cpp < /p>
#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;
}
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;
}
< /code>
gcc test_demo.cpp -lpthread -o test_demo
./test_demo
< /code>
I cat /proc/pid/smaps when the code run to getChar().So I have three smaps info. What confused me is that the smaps info is difference by how I declare the Array. Like this:
1、static const int array[LEN] = { 0 };< /code>
the smaps info shows that the PSS and RSS of test_demo increase about 40M
2、const int array[LEN] = { 0 };< /code>
the smaps info shows that the PSS and RSS of test_demo increase about 40M, and a block of memory is mapped for libc.so, meantime the size of the block of memory is 2048KB, PSS is 8KB.
3、int array[LEN] = { 0 };< /code>
only a block of memory is mapped for libc.so,meantime the size of the block of memory is 2048KB, PSS is 8KB.
I do not understand why this happened.Could someone tell me?
Подробнее здесь: https://stackoverflow.com/questions/719 ... ay-and-int
Какова разница между (статический массив Const int) 、 (Const int Array) и (int массив) в памяти ⇐ C++
Программы на C++. Форум разработчиков
1749467220
Anonymous
test_demo.cpp < /p>
#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;
}
< /code>
gcc test_demo.cpp -lpthread -o test_demo
./test_demo
< /code>
I cat /proc/pid/smaps when the code run to getChar().So I have three smaps info. What confused me is that the smaps info is difference by how I declare the Array. Like this:
1、static const int array[LEN] = { 0 };< /code>
the smaps info shows that the PSS and RSS of test_demo increase about 40M
2、const int array[LEN] = { 0 };< /code>
the smaps info shows that the PSS and RSS of test_demo increase about 40M, and a block of memory is mapped for libc.so, meantime the size of the block of memory is 2048KB, PSS is 8KB.
3、int array[LEN] = { 0 };< /code>
only a block of memory is mapped for libc.so,meantime the size of the block of memory is 2048KB, PSS is 8KB.
I do not understand why this happened.Could someone tell me?
Подробнее здесь: [url]https://stackoverflow.com/questions/71918995/what-the-difference-between-static-const-int-array-const-int-array-and-int[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия