Re: stack vs heap destruction problem
From: David White (no_at_email.provided)
Date: 02/01/05
- Next message: Pete Becker: "Re: strncpy copying beyond max length"
- Previous message: Shezan Baig: "Re: MS Visual Studio 6.0 compile failure"
- In reply to: Jamie Burns: "stack vs heap destruction problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 1 Feb 2005 11:23:43 +1100
"Jamie Burns" <reply_to_group@news.com> wrote in message
news:5XyLd.35041$v8.18137@fe2.news.blueyonder.co.uk...
> Hello,
>
> I have a function which uses an object I made. The object simply parses a
> text file and provides access to some of the data.
>
> I am trying to use it in a method of a different object.
>
> The problem is, when I declare it like this:
>
> {
> Properties properties("/tmp/data.properties");
> // use object...
Have you tried _not_ using the object to see what happens?
> }
>
> It causes a SEGFAULT when its destructor is called every time.
>
> But if I do:
>
> {
> auto_ptr<Properties> properties(new
Properties("/tmp/data.properties"));
> // use object...
> }
>
> Then it destructs perfectly every time.
>
> Is there an issue declaring things on the stack vs heap?
No, unless you don't have enough stack or you are doing something somewhere
that depends on which you choose.
> Why does this happen?
My guess is that you have a bug somewhere that, purely by accident,
manifests itself within the destructor when you use the automatic (stack)
version. Without seeing all the code being executed, that's the best I can
do.
DW
- Next message: Pete Becker: "Re: strncpy copying beyond max length"
- Previous message: Shezan Baig: "Re: MS Visual Studio 6.0 compile failure"
- In reply to: Jamie Burns: "stack vs heap destruction problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|