|
-
March 27th, 2015, 02:32 PM
#7
Re: atlsimpstr.h access violation error
 Originally Posted by saraswathisrinath
ok.
I have a doubt, today i received below errors from atlsimpstr.h,
1. nLength <=GetData() -> AllocLength
2. nrefs != 0
3. CStringData* pNewData = pOldData->Clone->Allocate(nLength, sizeof(XCHAR));
if(pNewData == NULL ) ThrowMemoryException
I refered https://social.msdn.microsoft.com/fo...dialog-pointer.
From this link, i have a doubt from string handling.
and confirmed using call stack.
Is the problem is nonproper handling of String?
A: 99.999% yes, is a problem of improperly handling of CString
You can simply reproduce this behavior writing the following simple code:
Code:
CString* pString = new CString(_T("Geo luvs strings"));
delete pString;
// ...
delete pString;
However, why the assert complains about nRefs?
An instance of a CString object has before its string buffer a CStringData structure.
Beside others, CStringData structure has a member named nRefs which is almost like a reference counter of a shared smart pointer. It avoids to have more than one CString object with different buffers having the same string contents. When assign one CString object to another new one, the new one gets the same string buffer and just CStringData::nRefs is incremented. Practically we can have more CString objects but in fact, only one string buffer in memory.
When delete one of "copies", CStringData::nRefs is decremented, and the string buffer is effectively deleted from memory only if CStringData::nRefs becomes 0 (zero).
Last edited by ovidiucucu; March 27th, 2015 at 03:09 PM.
Reason: typo
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|