RE: Re: Array of custom controls

"Michael Stephenson" <[email protected]> Wed, 1 Jun 2011 21:52:54 -0400
Newsgroups gmane.comp.windows.wtl
Message-ID <[email protected]>
I don’t think that the problem in this specific case is one of copying, rather it’s one of construction.  

 

When you call CAtlArray::Add() (the no-parameter version), it simply allocates memory for a new element.  It does not actually construct the element.  It basically calls SetCount() to grow the array and returns the new item count.

 

So, what you could do is call CAtlArray::SetCount() yourself to allocate memory for as many elements as you need, and then call CAtlArray::CallConstructors() to actually construct each of the items in place before you attempt to use the items.  I think this would work.

 

If you do create heap objects and just store the pointers in the array, you need to remember to call delete on those pointers when you’re done with them; emptying the array won’t do that for you, it will just deallocate the pointers.  If you are able to create them in-place as described above, I think you would need to call CAtlArray::CallDestructors() when you’re done with the array.  So, either way you have to do some cleanup.

 

I’m not sure if there isn’t a traits class other than CElementTraits that provides specialization for pointers; I usually just end up deleting the objects the pointers point to when I’m done with the object.

 

From: [email protected] [mailto:[email protected]] On Behalf Of Igor Tandetnik
Sent: Wednesday, June 01, 2011 8:27 PM
To: [email protected]
Subject: [wtl] Re: Array of custom controls

 

  

On 6/1/2011 7:48 PM, Bill wrote:
> What makes CWindowImpl not copyable? The thunking that goes on?

Yes. The object must stay alive for as long as the corresponding HWND is 
alive and receiving messages. It just doesn't make sense to copy 
CWindowImpl - the HWND only "knows" about one of them.
-- 
Igor Tandetnik





[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wtl/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/wtl/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/