What's the opposite of dynamic ?

D

dominic.connor

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.
 
G

Gavin Deane

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.

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
program.
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
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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.

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.
 
A

Andrey Tarasevich

Ok,
pX = new Stuff N];

Is dynamically created.
OK.

what about
Stuff x [N]; ?

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".
I can't call it stack allocation because it may be in a class, which
gets dynamically allocated.

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top