Click here to Skip to main content
15,912,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionProblem with pointers memory allocation on the same memory area Pin
Member 959508024-May-20 20:37
Member 959508024-May-20 20:37 
Hello,

We use a third party library for our grids. Each grid cell has a style, one member of which is the font:
C++
class CLibStyle
{
	[...]
	CLibFont m_pFont;
	[...]
};

During deserialization serialization in the library methods, the font is managed as follows:
C++
ar >> m_pFont;

For our part, we deserialize the styles line by line, column by column, then storing them in a map to use them later:
C++
CLibStyle * pStyle = NULL;
for (int nNumRow = 0; nNumRow ++; nNumRow <nNbRow)
	for (int nNumCol = 0; nNumCol ++; nNumCol <nNbCol)
	{
		pStyle = new CLibStyle();
		pStyle->Serialize(ar);
		mapStyle->AddTail(pStyle);
	}

So far it's very basic but this is where we have a big problem because it happens that this deserialization, as simple as it is, allocates pointers m_pFont on the same memory areas from one loop to another. With the same archive file, this problem does not necessarily arise depending on whether you are in Debug or in Release, or even differs from one PC to another. Unsure | :~

Afterwards, we inevitably have problems even if the pointers are destroyed ...

Any ideas for ensuring that pointers are not allocated on the same memory range?

Thanks a lot for your help.

modified 25-May-20 3:49am.

AnswerRe: Problem with pointers memory allocation on the same memory area Pin
Stephane Capo24-May-20 21:19
professionalStephane Capo24-May-20 21:19 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Richard MacCutchan24-May-20 21:29
mveRichard MacCutchan24-May-20 21:29 
AnswerRe: Problem with pointers memory allocation on the same memory area Pin
Richard MacCutchan24-May-20 21:25
mveRichard MacCutchan24-May-20 21:25 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Member 959508024-May-20 21:52
Member 959508024-May-20 21:52 
AnswerRe: Problem with pointers memory allocation on the same memory area Pin
Member 959508024-May-20 22:40
Member 959508024-May-20 22:40 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Richard MacCutchan24-May-20 22:54
mveRichard MacCutchan24-May-20 22:54 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Member 959508024-May-20 23:03
Member 959508024-May-20 23:03 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Richard MacCutchan24-May-20 23:19
mveRichard MacCutchan24-May-20 23:19 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Member 95950801-Jun-20 20:36
Member 95950801-Jun-20 20:36 
AnswerRe: Problem with pointers memory allocation on the same memory area Pin
phil.o25-May-20 0:21
professionalphil.o25-May-20 0:21 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Richard MacCutchan25-May-20 0:31
mveRichard MacCutchan25-May-20 0:31 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Member 959508025-May-20 1:25
Member 959508025-May-20 1:25 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
phil.o25-May-20 1:36
professionalphil.o25-May-20 1:36 
GeneralRe: Problem with pointers memory allocation on the same memory area Pin
Richard MacCutchan25-May-20 1:46
mveRichard MacCutchan25-May-20 1:46 
AnswerRe: Problem with pointers memory allocation on the same memory area Pin
Member 95950801-Jun-20 20:42
Member 95950801-Jun-20 20:42 
QuestionPrinting With Crystal Report Pin
a_alise21-May-20 11:09
a_alise21-May-20 11:09 
AnswerRe: Printing With Crystal Report Pin
_Flaviu22-May-20 0:12
_Flaviu22-May-20 0:12 
QuestionDynamic Created CEdit using CreateEx Pin
Beginner_mfc20-May-20 3:48
Beginner_mfc20-May-20 3:48 
AnswerRe: Dynamic Created CEdit using CreateEx Pin
Richard MacCutchan20-May-20 5:06
mveRichard MacCutchan20-May-20 5:06 
AnswerRe: Dynamic Created CEdit using CreateEx Pin
Victor Nijegorodov20-May-20 6:42
Victor Nijegorodov20-May-20 6:42 
QuestionC++ Pin
Member 1461181419-May-20 5:46
Member 1461181419-May-20 5:46 
AnswerRe: C++ Pin
Greg Utas19-May-20 6:08
professionalGreg Utas19-May-20 6:08 
GeneralRe: C++ Pin
Richard MacCutchan19-May-20 6:13
mveRichard MacCutchan19-May-20 6:13 
AnswerRe: C++ Pin
CPallini19-May-20 20:50
mveCPallini19-May-20 20:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.