What's the difference between Static and Dynamic Memory Allocation

and what are the advantages and disadvantages of them both?

Recommended Answers

All 8 Replies

Static allocation is fast, but set in stone. Dynamic allocation is slower, but you can grab varying chunks. This sounds a lot like a homework question.

nah, its not homework. I've been out of school for almost 2 yrs now and haven't coded in 3. i was reading up on it for this Software Engineer position and i could only find Dynamic Memory Allocation. There was nothing on Static memory allocation. So, i made a thread up. I told you this is going to be a second home for me. Thinking about getting a computer with there's still a flat panel special at Dell

thanx a lot as usual ;)

Static memory allocation is called a bunch of different things, whereas dynamic memory allocation is the term that's used most often for that concept.

>Static memory allocation is called a bunch of different things

hmmmmm...i think i saw something on static data storage. Is that the same thing?


oh i have my answers to that code i put up i'll put it up real soon

*about to type it up now*

It depends on the context. If we're talking about the structure of an executable file, then it's not the same. If we're talking about variables not allocated by new or malloc, then it probably is the same. If we're talking about linkage, then get ready to be confused. ;) I'm still not sure I understand linkage in C and C++. :D

i'm already confused lol

you lost me at >structure of an executable file

but let me type this code up real quick so you can see the answers, i think there was an error in the question they gave me (i'll explain later)

Static allocation is done at the time the program is written. The programmer reserves a set amount of memory for each use. That setting will be used each time the program runs.

Dynamic allocation is done while the program runs, adjusting the amount of memory for each use according to how much memory that use actually needs AT THIS TIME.

:mrgreen:

What's the difference between Static and Dynamic Memory Allocation

and what are the advantages and disadvantages of them both?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.