Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of "statically allocated"?

Tags:

c

pthreads

http://linux.die.net/man/3/pthread_mutex_init

In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes that are statically allocated. The effect shall be equivalent to dynamic initialization by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed.

I know about dynamic allocation. What is the meaning of "statically allocated"?

My question here is to understand the meaning of "statically" allocated. I posted the quote from the man page to provide a context, only.

like image 626
Aquarius_Girl Avatar asked Jun 02 '15 00:06

Aquarius_Girl


Video Answer


1 Answers

Statically allocated means that the variable is allocated at compile-time, not at run-time. In C, this can be a global variable at the file scope or a static variable in a function.

A good overview is found here: http://en.wikipedia.org/wiki/Static_memory_allocation

Variables on the stack (i.e., local variables in functions that do not have the static keyword) are allocated when the function is called, sometimes multiple times when a function is called recursively. So they are conceptually different from static memory allocation (which only happens once per program).

like image 91
mdd Avatar answered Oct 22 '22 03:10

mdd