Re: CListCtrl, custom item data and allocation policy
- From: "Michael K. O'Neill" <mikeathon2000@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 16 Jan 2008 13:18:03 -0800
"Mosfet" <anonymous@xxxxxxx> wrote in message
news:478e6385$0$2739$426a74cc@xxxxxxxxxxxxxxx
Hi,
When using a CListCtrl you can associate some custom data via the
SetItemData method.
The problem is it takes a DWORD argumentr that can reference a value or a
pointer to an allocated structure.
When destroying this CListCtrl is there any ways of determining if it
needs to be deallocated.
For instance, let's say I have a CMyListCtrl inheriting from CListCtrl
used in two different dialogs.
In one dialog I call SetItemData passing a DWORD value representing a
numeric value and in the second one I pass a pointer to an allocated chunk
of memory.
In the destructor how doI know if I need to call delete ?
I would use the item data to point always to the same kind of structure,
say, MyStruct, which includes both the numeric item as well as a pointer to
the allocated structure. If the allocated structure does not exist, the
pointer should be set to NULL. Then you can always call delete on the
pointer, since deletion of a NULL pointer is always allowed.
Of course, with this method, you would always need to allocate a MyStruct
for each item, and always delete it too. However, the MyStruct structure
would be small (maybe only 12 bytes in this example, 4 for the integer and 8
for the pointer) and presumably would be so much smaller than the ultimate
structure, that this technique would make sense.
.
- References:
- CListCtrl, custom item data and allocation policy
- From: Mosfet
- CListCtrl, custom item data and allocation policy
- Prev by Date: Re: Is CArray best for this...
- Next by Date: Re: CListCtrl, custom item data and allocation policy
- Previous by thread: Re: CListCtrl, custom item data and allocation policy
- Next by thread: Re: CListCtrl, custom item data and allocation policy
- Index(es):
Relevant Pages
|