LPSTR how to free memory after using
Suppose i have a LPSTR variable. How do i free the memory after using the variable. Is it
LPSTR szFileName = GetSBCSB开发者_如何学运维uffer(sFilePath); // sFilePath is a CString
delete szFileName;
OR
delete []szFileName;
Kindly advise
If memory was allocated using new char[SIZE]
then it needs to be freed using delete []
.
You can't answer that question without knowing the specifics of GetSBCSBuffer. Hopefully whoever wrote the function left you with code and/or documentation so you can see where the string comes from. It might be that neither of your alternatives is correct. The author of GetSBCSBuffer might have used a different memory allocator or returned a pointer to a location internal to sFilePath. In the last case it would be very bad to call any deallocator.
I just noticed you answered the question yourself in your comment to elder_george's answer. The implementation used new[] so you need to delete[].
精彩评论