We mainly study about heap and stack data structures which act as storage allocation area in memory. Is it that queue is also a storage allocation area in memory? As far as I know, process control blocks are made in OS region and actually they also act as storage allocation area only so can I consider queue to be a storage allocation area in memory?
Asked By : radhika
Answered By : Gilles
You've been misled by homonyms.
There is a data structure called stack: a container where items can be added at any time but only the most recently added can be removed. And there is an area in memory called stack, which is where function arguments, local variables, return values and return addresses are stored¹. There's one stack memory area per thread. The two concepts have the same name because the stack memory area is organized as a stack data structure: an item is added when a function call is executed, and it is removed upon return from a function; since function calls are nested, the item that's removed is the last one that was added and not yet removed.
There is a data structure called heap: a tree of ordered items where each node holds a smaller value than all of its children². And there is an area in memory called heap, which is where storage is allocated dynamically. There is one heap per process. The two concepts are completely unrelated, they have the same name because there's a finite supply of English words with roughly the right connotations and it happens that the same word was picked for both.
There is no reason why a word that is a name for a data structure should also be a name for an area in memory. There can be queue data structures in an operating system, of course, but there's no area in memory that's called "the queue".
Process control blocks are not organized as a queue, and they are not a storage allocation area, they're just a common name for the place in memory where the operating system stores information about each process (and not every operating system has all the information in one place, so not every OS's description mentions a "process control block").
¹ This is just the 10000-foot view. Return addresses and arguments could be placed in different areas, some arguments typically end up in registers, etc.
² That's a min-heap; a max-heap is a tree where each node holds a larger value than all of its children.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/50940
0 comments:
Post a Comment
Let us know your responses and feedback