Thread: C++ Arrays
View Single Post
Old 11-09-2006, 07:37 PM   #21 (permalink)
Sep102
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

You've never used the syntax because placement-new isn't really used all too often, at least as far as I've seen. It can be really useful when you actually need it, but in general standard new provides most of the functionality you would need (Or, at least, that's my take on the matter).

And, technically my (milt's) example uses the same method for memory allocation, I just construct the instances of the Month in a different way, closer to the way C# does it then copied them over to where I was going to persist them.

Really, you wouldn't do it your way either, in general, maybe (Probably not still though, if I was expecting to construct multiple objects at once as an array on the heap, I'd provide some Initialize() function or something of the sort rather than calling the constructor on each of them after allocating them), but at least in this instance it's not really a good idea to re-create the months every time, at least as it is. Like I said earlier, it would be a better idea to create them once then make a copy of them each time they're needed for a new instance (if it's mutable, of course), of which my example is very well suited to perform.

Last edited by Sep102; 11-09-2006 at 07:40 PM.
Sep102 is offline   Reply With Quote