What's the opposite of dynamic ?

Discussion in 'C++' started by dominic.connor, Mar 20, 2007.

  1. Ok,
    pX = new Stuff N];

    Is dynamically created.

    what about
    Stuff x [N]; ?
    To me saying it's statically allocated is wrong, because that goes to
    static variables.
    I can't call it stack allocation because it may be in a class, which
    gets dynamically allocated.
    dominic.connor, Mar 20, 2007
    1. Advertisements

  2. dave_mikesell, Mar 20, 2007
    1. Advertisements

  3. dominic.connor

    Gavin Deane Guest

    C++ defines three kinds of storage duration:

    Dynamic storage duration for dynamically allocated objects like in
    your first example that exist until explicitly deleted.
    Static storage duration for objects like globals and those declared
    static which exist from their point of definition until the end pf the
    And the third is called automatic storage duration - for things that
    are automatically destroyed at the end of the scope in which they were
    defined - i.e. local variables.

    Member objects have the same storage duration as of the object of
    which they are part.

    Gavin Deane
    Gavin Deane, Mar 20, 2007
  4. You seem to be confusing C++ with Java, where all instances of classes
    are allocated on the heap (or whatever they call it) and only builtin
    typed (and references) are on the stack. In C++ things are where you put
    them, consider the following:

    class Foo
    // ...

    int main()
    Foo a[5];

    Here we declare an array of 5 Foo-objects all on the stack.
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Mar 20, 2007
  5. Firstly, it is important to keep in mind that the notion of being "created"
    (they way you use it) applies only to object _definitions_ or dynamic allocations.

    Secondly, the answer depends on the context. If you write the above as a
    _definition_ in local scope, then it has automatic storage duration, i.e. you
    can call it "automatically created". In namespace scope it would have static
    storage duration, i.e. it is "statically created".
    That's a completely and significantly different situation. If the above is
    written in a class definition, then it is a _declaration_ of a class member
    that, which is _not_ _a_ _definition_. The notion of being "created" does not
    apply in this case at all. It is not created yet, neither dynamically nor in any
    other fashion.
    Andrey Tarasevich, Mar 20, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.