To my understandings, dynamic allocation is preferred to declaring local variables when
- you need to allocate a large amount of data compared to the stack size, and/or
- you want to control the duration of it dynamically.
But AFAIK global variables are allocated on the data segment, which is also fairly large compared to the stack.
Suppose I have a large variable whose lifetime will be throughout the entire program and the concerns are only its size. Will there be still any disadvantages in declaring it globally instead of calling malloc?
People often warn that global variables are evil because they make the code complex and unclear, but I don't think I should care for this because in my case the file scope is small.