ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

acutDelString And delete[]

5 REPLIES 5
Reply
Message 1 of 6
869376419
417 Views, 5 Replies

acutDelString And delete[]

ACHAR *chArxPath = NULL;
acutUpdString(_T("command"), chArxPath);

acutDelString(chArxPath);

 

Can I use "delete [] chArxPath"?

 

Is something diffrent?

Because I use new ACHAR[] sometime.

 

5 REPLIES 5
Message 2 of 6
tbrammer
in reply to: 869376419

This is the inline implementation of acutDelString() in acutmem.h:

 

inline void acutDelString(wchar_t *& pString)
{
    ::acutDelBuffer((void * &)pString);
}

As you can see it calls acutDelBuffer(void *& pString). This can't be exactly the same as delete [] pString.

So I would not recommend to mix new ACHAR []  and acutDelString().

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 3 of 6
syx_lemans
in reply to: 869376419

In my opinion, ACHAR *chArxPath = NULL define a string literal. The string literal is initialised into read-only memory segment by the compiler. There is no initialisation or removal done at run-time. So no need to delete.

Message 4 of 6
artc2
in reply to: 869376419

The acut string methods work with the acdb heap. If you have a string allocated from the acdb heap (i.e. a string allocated by an acut function or obtained from an ARX/DBX API function), it is best to use the acut methods to free the string to be sure that the free occurs on the correct heap.
Message 5 of 6
tbrammer
in reply to: syx_lemans

 

ACHAR *chArxPath = NULL;

You don't need to free chArxPath at this point. Obviously.

 

acutUpdString(_T("command"), chArxPath);

Makes a deep copy of "command" and sets chArxPath to point to this new allocated string. It will not just copy the pointer.
Now you have to free chArxPath with acutDelString(chArxPath) if you don't need it anymore to avoid memory leaks. See docs for acutUpdString().

 

I suppose this:

ACHAR *chArxPath = L"old";
acutUpdString(L"new", chArxPath);

would cause an exception because acutUpdString() will release the memory for chArxPath if it is !=NULL.
But chArxPath points to the fixed memory segment L"old", that can't be freed.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 6 of 6
869376419
in reply to: tbrammer

 I used new ACHAR[] and acutUpdString both,. So I have to remember achar from which one. This is my problem mainly.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost