Okay. In that case the idea of having only a single object may not hold
good. If your object constructor and destructor is not doing any complex
things (with respect to runtime), then creating multiple objects are fine.
But remember, even in that case, there is a cost involved in creating and
deleting an object.
Alternatively you can create the necessary dir objects upfront and store it
in a vector and called only the process function within the for loop.
If your requirement is something like you need to call a specific object for
a given specific input name, then instead of vector, you can store the
objects
in a map with the key as the input name and value as the dir object. This
may improve your performance.

~Thanga


On Sat, Oct 3, 2009 at 12:07 AM, Rick <[email protected]> wrote:

>
>
>
> >Date: Fri, 02 Oct 2009 14:18:19 -0400
> >To: [email protected] <c-prog%40yahoogroups.com>
> >From: Rick <[email protected] <Mowgli53%40GMail.Com>>
> >Subject: Re: [c-prog] class object destruction?
> >Bcc: ƒ\01-personalities\[email protected] <P-Mowgli53%40GMail.Com>
>
> >
> >At 10/2/2009 01:56 PM, you wrote:
> >>Hi Rick,
> >>Each time inside the loop, dir object will be created and destroyed.
> >>The first instance will not stay around. It will be destroyed when the
> first
> >>iteration of the for loop completes.
> >>The dir object is statically created inside the for loop and the life
> time
> >>and scope of such objects will be local to the block where it is created.
> >>These objects generally gets created on the stack and will be destroyed
> >>automatically when it goes out of scope.
> >>The destructor will be called properly during such destruction.
> >>In this case for each iteration of the for loop, the constructor and
> >>destructor of dir object will be called.
> >>
> >>I feel this is not the best way of doing it. There are lot of other
> better
> >>ways to do that.
> >>If i am not wrong, i would say that the way dir object is modelled was
> >>wrong.
> >>Instead of creating object every time, it would rather can be created
> once.
> >>It should expose a public interface for processing different
> >>directory/files.
> >>There are lot of other smart people in this group. I believe they can
> give
> >>you suggestions on better way of designing it.
> >>
> >>Thanks,
> >>Thanga
> >
> >Thank you for your thoughts.
> >
> >Initially I put the directory and path names
> >into the process() calling list but changed it
> >later. I could put it back the other way. In
> >fact, that may help with another issue I have of
> >maintaining values across instantiations.
> >
> >~Rick
>
> On second thought, I don't think this will work
> (create only one object). The reason, I now
> remember, that i changed the code was because
> each path that a user specifies becomes a new
> "root" path to search. I recurse through all
> directories from that path down. So I need a "base" point to anchor to.
>
> ~Rick
>
>  
>


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

Reply via email to