G
Guest
Hi again,
I've defined the following structure:
typedef struct _MYSTRUCT{
CTypedPtrArray<CPtrArray,SECSTRUCT*> a;
CTypedPtrArray<CPtrArray,SECSTRUCT*> b;
BYTE d;
BOOL c;
USHORT e;
}MYSTRUCT,*PMYSTRUCT;
Additionally, there's a CTypedPtrArray<CPtrArray,MYSTRUCT*> mydata;.
Now, all these arrays are filled like this:
MYSTRUCT *m = new MYSTRUCT;
//[...] fill in data. Data for a and b is also created by 'new' and added to
the list
mydata.Add(m);
The incident happens when I try to free all the allocated memory again. So,
I walk the array in mydata:
MYSTRUCT *a = NULL;
for(int i = 0; i < mydata.GetCount();i++)
{
a = (MYSTRUCT*)mydata.GetAt(i);
for(int x = 0; x < a->a.GetCount();x++)delete (SECSTRUCT*)a->a.GetAt(x);
//same for a->b goes here
//Now, this is critical:
delete a;
}
When I execute the last 'delete'- statement the program goes on rampage
(errors in different places - they don't occur when I don't delete a.
(Perhaps the whole has got something to do with these MFC classes
CTypedPtrArray and that therefore sizeof(MYSTRUCT) is not const - or I may be
completely wrong).
Any ideas why this happens?
Thanks
Peter
I've defined the following structure:
typedef struct _MYSTRUCT{
CTypedPtrArray<CPtrArray,SECSTRUCT*> a;
CTypedPtrArray<CPtrArray,SECSTRUCT*> b;
BYTE d;
BOOL c;
USHORT e;
}MYSTRUCT,*PMYSTRUCT;
Additionally, there's a CTypedPtrArray<CPtrArray,MYSTRUCT*> mydata;.
Now, all these arrays are filled like this:
MYSTRUCT *m = new MYSTRUCT;
//[...] fill in data. Data for a and b is also created by 'new' and added to
the list
mydata.Add(m);
The incident happens when I try to free all the allocated memory again. So,
I walk the array in mydata:
MYSTRUCT *a = NULL;
for(int i = 0; i < mydata.GetCount();i++)
{
a = (MYSTRUCT*)mydata.GetAt(i);
for(int x = 0; x < a->a.GetCount();x++)delete (SECSTRUCT*)a->a.GetAt(x);
//same for a->b goes here
//Now, this is critical:
delete a;
}
When I execute the last 'delete'- statement the program goes on rampage
(errors in different places - they don't occur when I don't delete a.
(Perhaps the whole has got something to do with these MFC classes
CTypedPtrArray and that therefore sizeof(MYSTRUCT) is not const - or I may be
completely wrong).
Any ideas why this happens?
Thanks
Peter