Topic: When Is Memory allocated for this
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/02/25 Raw View
In article <891tf4$ecu$0@205.138.136.177>, M. Thomas Groszko
<mgroszko@novagate.com> writes
>void SomeRoutine(void)
>{ int abc;
> if (something == somethingelse)
> { int cde[1000];<<================ when is this allocated
> do some work;
> } else
> { do some other work;
> }
>}
>
>I cannot find in the standard rules to specifically say when "cde" will have
>the storage allocated. Is this up to the implementer? The standard I think
>clearly says it goes away before the code block is left.
int is probably a bad choice for your question. If you were declaring
an array of a user defined type with a non-trivial ctor you would find
that it (and the dtor) was called 1000 times only if the control
expression evaluated to true. However the compilers has almost certainly
allocated memory in the local stack frame (or equivalent) on entry to
the containing block.
Francis Glassborow Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Nick Ambrose <nick@ixia.com>
Date: 2000/02/28 Raw View
Francis Glassborow wrote:
> In article <891tf4$ecu$0@205.138.136.177>, M. Thomas Groszko
> <mgroszko@novagate.com> writes
> >void SomeRoutine(void)
> >{ int abc;
> > if (something == somethingelse)
> > { int cde[1000];<<================ when is this allocated
> > do some work;
> > } else
> > { do some other work;
> > }
> >}
> >
> >I cannot find in the standard rules to specifically say when "cde" will have
> >the storage allocated. Is this up to the implementer? The standard I think
> >clearly says it goes away before the code block is left.
>
> int is probably a bad choice for your question. If you were declaring
> an array of a user defined type with a non-trivial ctor you would find
> that it (and the dtor) was called 1000 times only if the control
> expression evaluated to true. However the compilers has almost certainly
> allocated memory in the local stack frame (or equivalent) on entry to
> the containing block.
>
but won't the compiler (in this case) just generate code for the storage only if
the condition is true ?
i.e. on a particular architecture, something like ESP += 1000*sizeof (int) ?
I wouldn't think it would get allocated on the stack (if the implementation uses
such a thing) unless the condition was true.
nick
--
Nick Ambrose
Senior Software Engineer
Ixia Communications, Inc.
<mailto:nick@ixia.com>
(818) 871-1800 x160
http://www.ixia.com
Ixia...
When the test really counts.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/02/28 Raw View
In article <38B6E9DC.6668F545@ixia.com>, Nick Ambrose <nick@ixia.com>
writes
>but won't the compiler (in this case) just generate code for the storage only if
>the condition is true ?
>i.e. on a particular architecture, something like ESP += 1000*sizeof (int) ?
>I wouldn't think it would get allocated on the stack (if the implementation uses
>such a thing) unless the condition was true.
That is entirely a decision for the implementor of the compiler and
almost certainly outside your control. What I wrote described what many
common compilers for Intel based platforms do.
Francis Glassborow Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "M. Thomas Groszko" <mgroszko@novagate.com>
Date: 2000/02/29 Raw View
I chose int because I have several of these very large arrays in several
blocks in the same function which all seem to be allocated at the same time
up front.
Francis Glassborow <francis@robinton.demon.co.uk> wrote in message
news:26O4icAJoZt4Ewl9@robinton.demon.co.uk...
> In article <891tf4$ecu$0@205.138.136.177>, M. Thomas Groszko
> <mgroszko@novagate.com> writes
> >void SomeRoutine(void)
> >{ int abc;
> > if (something == somethingelse)
> > { int cde[1000];<<================ when is this allocated
> > do some work;
> > } else
> > { do some other work;
> > }
> >}
> >
> >I cannot find in the standard rules to specifically say when "cde" will
have
> >the storage allocated. Is this up to the implementer? The standard I
think
> >clearly says it goes away before the code block is left.
>
> int is probably a bad choice for your question. If you were declaring
> an array of a user defined type with a non-trivial ctor you would find
> that it (and the dtor) was called 1000 times only if the control
> expression evaluated to true. However the compilers has almost certainly
> allocated memory in the local stack frame (or equivalent) on entry to
> the containing block.
>
>
>
> Francis Glassborow Journal Editor, Association of C & C++ Users
> 64 Southfield Rd
> Oxford OX4 1PA +44(0)1865 246490
> All opinions are mine and do not represent those of any organisation
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "M. Thomas Groszko" <mgroszko@novagate.com>
Date: 2000/02/25 Raw View
void SomeRoutine(void)
{ int abc;
if (something == somethingelse)
{ int cde[1000];<<================ when is this allocated
do some work;
} else
{ do some other work;
}
}
I cannot find in the standard rules to specifically say when "cde" will have
the storage allocated. Is this up to the implementer? The standard I think
clearly says it goes away before the code block is left.
Thanks
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: daniel@reichardt.ch (Daniel Hartmeier)
Date: 2000/02/25 Raw View
On Fri, 25 Feb 2000 03:30:13 CST, M. Thomas Groszko wrote:
>void SomeRoutine(void)
>{ int abc;
> if (something == somethingelse)
> { int cde[1000];<<================ when is this allocated
> do some work;
> } else
> { do some other work;
> }
>}
>
>I cannot find in the standard rules to specifically say when "cde" will have
>the storage allocated. Is this up to the implementer? The standard I think
>clearly says it goes away before the code block is left.
I don't see why you would care when the object is allocated. But
the standard defines when the object is initialized:
6.7 Declaration statement [stmt.dcl]
2 Variables with automatic storage duration are initialized
each time their declaration-statement is executed. Variables
with automatic storage duration declared in the block are
destroyed on exit from the block.
Does this answer your question, or do you really want to
distinguish between allocation and initialization?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]