在我提出问题之前,让我解释一下我的环境:
(o/i)stream
,char
数组,char*
,c_str()
函数,struct
和struct*
, static string
数组,#define
,enums
,FILE*
,vector<>
和常规数组int
,string
等) 。其中一些数据类型作为参数传递给函数。popen
执行一些系统命令,其中使用生成的FILE*
现在应用程序运行了三天,我注意到每天虚拟存储(来自top
命令的VSZ)增加了32 KB字节。错误地重启了设备,我再次启动了应用程序,VSZ值从每个新启动时的常规值开始(大约2532 KB)。
我开发了另一个应用程序,它监视应用程序的VSZ值,并在每个应用程序上使用crontab
进行调度,以启动监视器。我注意到在白天的某个时刻我注意到的32 KB每小时发生了4 KB。
所以主要的问题是,VSZ增加的原因是什么?最终它会达到一个限制,导致系统崩溃,这是我关心的因为设备有大约。 27 MB RAM。
更新:除VSZ值外,RSS也会增加。我在valgrind --leak-check=full
下运行了应用程序,在第一次录制之后我中止了应用程序,并且多次出现以下消息!。
==28211== 28 bytes in 1 blocks are possibly lost in loss record 15 of 52
==28211== at 0x4C29670: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28211== by 0x4EF33D8: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.19)
==28211== by 0x4EF4B00: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib64/libstdc++.so.6.0.19)
==28211== by 0x4EF4F17: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.19)
==28211== by 0x403842: __static_initialization_and_destruction_0 (gatewayfunctions.h:28)
*==28211== by 0x403842: _GLOBAL__sub_I__Z18szBuildUDPTelegramSsii (gatewayfunctions.cpp:396)
==28211== by 0x41AE7C: __libc_csu_init (elf-init.c:88)
==28211== by 0x5676A94: (below main) (in /lib64/libc-2.19.so)
出现相同的消息,但带有*
的行显示的文件名不同。另一件事我注意到,文件gatewayfunctions.h
的第28行是一个静态字符串数组声明,这个数组只用在两个文件中。有什么建议吗?