主页(http://www.kuwanit.com):嵌入式系统节省内存的解决方法
0.0 0.0 /home/charles/tmp/test 1092 1092 2216
下面举个例子说明。
dlclose()后:
$ ps -p $(pidof test) -o %cpu,%mem,cmd,rss,rsz,vsz,trs
在dlopen执行前,程序内存使用:
0.0 1.0 /home/charles/tmp/test 42000 42000 43192 1
$ ps -p $(pidof test) -o %cpu,%mem,cmd,rss,rsz,vsz,trs
%CPU %MEM CMD RSS RSZ VSZ TRS
$ ps -p $(pidof test) -o %cpu,%mem,cmd,rss,rsz,vsz,trs
0.0 0.0 /home/charles/tmp/test 1092 1092 2216 1
$ ps -p $(pidof test) -o %cpu,%mem,cmd,rss,rsz,vsz,trs
%CPU %MEM CMD RSS RSZ VSZ TRS
%CPU %MEM CMD RSS RSZ VSZ TRS
$ gcc test.c -g -o test -ldl -l1 -L.
%CPU %MEM CMD RSS RSZ VSZ TRS
打开gdb,执行 gdb test,
$ gcc 1.c -shared -fpic -g -o lib1.so
%CPU %MEM CMD RSS RSZ VSZ TRS
dlopen()执行后:
ps -p $(pidof test) -o %cpu,%mem,cmd,rss,rsz,vsz,trs
执行 dlclose()后:
一种方法是把需要支持的功能做成共享库的形式,需要这个功能的时候加载共享库,不需要的时候卸载共享库,从而把内存释放出来。
打开APP阅读更多精彩内容点击阅读全文
内存又恢复到上次的数值了。
可以看到,大部分用到的内存都释放掉了。
0.0 0.0 /home/charles/tmp/test 696 696 2084 1
0.0 1.0 /home/charles/tmp/test 42008 42008 43192 1
然后如果执行下一次循环, dlopen()后:
嵌入式系统内存往往是有限制的(成本考虑),因此需要尽量支持更多的功能,同时尽量减少使用的内存。
发表评论愿您的每句评论,都能给大家的生活添色彩,带来共鸣,带来思索,带来快乐。