- 论坛徽章:
- 0
|
本帖最后由 0x5a5a 于 2013-01-28 10:30 编辑
大家好,我写了两个测试程序,差别只在于是否 new 了一个对象,但是虚拟内存使用量相差有 64M。
不过同样的两份代码,在其它的机器上编译运行就没有这个问题,请大家帮看看,是不是环境设置有什么问题?谢谢!
vm_n.cpp —— 不创建对象
vm_y.cpp —— 创建对象- cat ./vm_n.cpp
- #include <unistd.h>
- #include <pthread.h>
- class TestClass
- {
- public:
- TestClass() {}
- };
- void* fo(void* param) {
- //TestClass* c = new TestClass();
- while(1) sleep(1);
- }
- int f() {
- pthread_t tid;
- pthread_create( &tid, NULL, fo, NULL);
- }
- int main() {
- f();
- while(1) sleep(1);
- }
复制代码- cat ./vm_y.cpp
- #include <unistd.h>
- #include <pthread.h>
- class TestClass
- {
- public:
- TestClass() {}
- };
- void* fo(void* param) {
- TestClass* c = new TestClass();
- while(1) sleep(1);
- }
- int f() {
- pthread_t tid;
- pthread_create( &tid, NULL, fo, NULL);
- }
- int main() {
- f();
- while(1) sleep(1);
- }
复制代码- # g++ ./vm_y.cpp -o vm_y -lpthread
- # g++ ./vm_n.cpp -o vm_n -lpthread
- # ps -ef|grep vm
- root 17886 15362 0 10:05 pts/1 00:00:00 ./vm_n
- root 17888 15362 0 10:05 pts/1 00:00:00 ./vm_y
- root 17891 17546 0 10:05 pts/0 00:00:00 grep vm
- # top
- PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
- 17886 root 20 0 24268 964 800 S 0.0 0.1 0:00.00 vm_n
- 17888 root 20 0 89804 976 812 S 0.0 0.1 0:00.00 vm_y
复制代码 |
|