Quick question: I'm a C # guy debugging a C ++ application, so I'm not used to memory management.
In the following code:
for(int i = 0; i < TlmMsgDB.CMTGetTelemMsgDBCount(); i++) { CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i); CMT_SINT32_Tdef id = telm->CMTGetPackingMapID(); ManualScheduleTables.SetManualMsg(i,id); ManualScheduleTables.SetManExec(i,false); }
Am I losing memory on every b / c iteration CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i);? The CMTGetTelemetryMsg (int) method returns a pointer.
CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i);
Do I need a " delete telm;" at the end of each iteration?
delete telm;
There is no global answer to this question.
It really depends on how the person implemented the function with the return value.
, : TlmMsgDB.CMTGetTelemetryMsg
TlmMsgDB.CMTGetTelemetryMsg
. TlmMsgDB.CMTGetTelemetryMsg , . - ,
TlmMsgDB.CMTGetTelemetryMsg(i) CMTTelemetryMsgCls, . , delete , , , . , , - , .
TlmMsgDB.CMTGetTelemetryMsg(i)
CMTTelemetryMsgCls
delete
. , CMTGetTelemetryMsg, , , ... . , , , . TlmMsgDB, .
. TlmMsgDB.CMTGetTelemetryMsg(i).
( "new Something()" ), , , - . , "get" - , , . , , , .
, .:) .;)
, . , delete, - -, , . :
1) , , , , (, malloc, mmap, brk) , . , , , , CMTGetPackingMapID.
2) , " , ", - sysems strace/ltrace. , , , .
3) , ,
, ++ - , , . , , 10 , . (), malloc - .
Try using a profiler. It can provide you with some useful memory management information inside the process that will be profiled. Or, even better, you can use something like SoftICE, this allows you to set a breakpoint on any function that allocates memory, such as HeapAllocEx. Using such a tool, you will definitely determine the actual behavior of the 3rd party code, even without sources.
Source: https://habr.com/ru/post/1739500/More articles:TCP Socket Communication Limit - c #limit simultaneous user login to Plone / Zope - limitShowing labels in BibTex [LaTeX] - latexmultidimensional php array smarty loop - arraysGetting data types from an arbitrary SQL query in SQL Server 2008 - sqlFileSystemWatcher runs as a licensed user - c #Access 2007: Unrecognized Database Format - ms-access-2007MATLAB variable editor in Python - pythonWhy not use GDI + from ASP.NET - asp.netIQueryable :; / iframe> The extension method does not work - c #All Articles