怪现象,这个结构的内存怎么释放

zqqq1 2003-06-04 09:23:57
不知各位大虾是否用过snmp编程,其中有一个结构是simOID,
申请内存时是 simLPOID pOID = new simOID;
这没有什么,当执行如下函数时:SnmpStrToOid(name,pOID);
其中name是CString 类型的,比如值为"asdfas".
这时候你打开任务管理器,你会发现内存有所增长,
如果着一些写在一个函数内(假设,这样方便些),最后用一个判断语句
if(pOID !=NULL)
delete pOID ;
但是你会发现内存根本没有下降,不知道这是怎么回事?
请大家帮忙。
如果你不懂snmp,可以在你的头文件中加上以下语句:
#include "winsnmp.h"
#include "mgmtapi.h"
#pragma comment("lib,Wsnmp32.lib");
#pragma comment("lib,mgmtapi.lib");
#pragma comment("lib,snmpapi.lib");

写一个函数试一试,帮忙解决以下问题。谢谢各位了
...全文
19 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
windbells 2003-06-05
  • 打赏
  • 举报
回复
For output parameters
A call to any of the following functions results in the implementation allocating memory for an smiOID or an smiOCTETS descriptor: SnmpGetVb, SnmpEncodeMsg, SnmpOidCopy, SnmpContextToStr, and SnmpStrToOid.

Because the implementation allocates the memory for these output objects, the application must call the SnmpFreeDescriptor function to deallocate the resources. This function enables the implementation to free the memory allocated for the ptr member of these structures.

ahao 2003-06-05
  • 打赏
  • 举报
回复
可能太小了看不出,分配1000个
在delete看看
yangang000 2003-06-05
  • 打赏
  • 举报
回复
当程序退出时内存会不会释放?Windows可能会保留刚分配的内存区域以提高程序速度,你可以试一试分配其它类型的内存的情况!这个问题我没注意过,但有可能是这样。
zqqq1 2003-06-05
  • 打赏
  • 举报
回复
这个函数是将name字符串转化为一个在snmp中特定的一个结构。希望大家帮帮忙啊
flybird22 2003-06-05
  • 打赏
  • 举报
回复
不用CString试一试
ahao 2003-06-04
  • 打赏
  • 举报
回复
不明白,SnmpStrToOid(name,pOID);的作用是什么?
传回一个new出来的pOID?
guoyin 2003-06-04
  • 打赏
  • 举报
回复
帮你顶了。

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧