What's automatic memory allocation ?

Hi there!

Can you tell me what Automatic memory allocation allocates ? I know that:

* Static memory allocation allocates global and static variables (at compile-time)
* Dynamic memory allocation allocates dynamic variables (at runtime)

So - according to this - Automatic memory allocation allocates local variables (at runtime), doesn't it ?
Automatic memory is used on normal variables.
The following two lines are equivalent with the current standard:
1
2
int x;
auto int x;



1
2
3
4
5
6
7
8
9
10
11
int *Dynamic;

{
    static int Static; // allocated only once - at runtime -
    int Auto; // allocated each time the current { } block is executed
    Dynamic = new int; // allocated when you want - each call of new -
} // Auto is destructed when out of scope

delete Dynamic; // Dynamic deleted whenever you want

// Static is destructed when the program ends 
Last edited on
So - simply puts - Automatic memory allocation allocates local variables which are automatic :)
No. Simply put, automatic variables are named variables on the stack.
I know... But who does allocate them - Automatic memory allocation ?
As in who does the allocation?
The compiler - hence, automatic.
Global variables are allocated by the compiler, but they are not auto.
The compiler - hence, automatic.


And the name of this allocation is Automatic memory allocation, right ?

( http://en.wikipedia.org/w/index.php?title=Automatic_memory_allocation&redirect=no )
They're automatic because they're automatically recreated each time the scope of execution is entered, and destroyed when the scope is exited.

C99 6.2.4
http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf
I've got one more question: is Stack-based memory allocation the same thing as Automatic memory allocation allocates ?
Last edited on
Yes
In my opinion, as the name says:

* Stack-based memory allocation allocates space for auto variables,
* Heap-based memory allocation allocates space for dynamic variables (created by 'new' operator),
* Static memory allocation allocates space for global and static variables.

Is that right ?
Yes
OK, thanks Bazzy ;)
Topic archived. No new replies allowed.