What is the origin of the term “heap” for the free store?

吃可爱长大的小学妹 提交于 2019-11-27 08:02:47

Knuth rejects the term "heap" used as a synonym for the free memory store.

Several authors began about 1975 to call the pool of available memory a "heap." But in the present series of books, we will use that word only in its more traditional sense related to priority queues. (Fundamental Algorithms, 3rd ed., p. 435)

For what it's worth, ALGOL68, which predated C, had an actual keyword heap that was used to allocate space for a variable from the "global heap", as opposed to loc which allocated it on the stack.

But I suspect the use may be simply because there's no real structure to it. By that, I mean that you're not guaranteed to get the best-fit block or the next block in memory, rather you'll take what you're given depending on the whims of the allocation strategy.

Like most names, it was probably thought of by some coder who just needed a name.

I've often heard of it referred to as an arena sometimes (an error message from many moons ago saying that the "memory arena was corrupted"). This brings up images of chunks of memory doing battle in gladiatorial style inside your address space (a la the movie Tron).

Bottom line, it's just a name for an area of memory, you could just as well call it the brk-pool or sbrk-pool (after the calls to modify it) or any of a dozen other names.

I remember when we were putting together comms protocol stacks even before the OSI 7-layer model was a twinkle in someone's eye, we used a layered approach and had to come up with names at each layer for the blocks.

We used blocks, segments, chunks, sections and various other names, all which simply indicated a fixed length thing. It may be that heap had a similar origin:

Carol: "Hey, Bob, what's a good name for a data structure that just doles out random bits of memory from a big area?"

Bob: "How about 'steaming pile of horse dung'?"

Carol: "Thanks, Bob, I'll just opt for 'heap', if that's okay with you. By the way, how are things going with the divorce?"

It's named a heap for the contrasting image it conjures up to that of a stack.

  • In a stack of items, items sit one on top of the other in the order they were placed there, and you can only remove the top one (without toppling the whole thing over).

  • In a heap, there is no particular order to the way items are placed. You can reach in and remove items in any order because there is no clear 'top' item.

It does a fairly good job of describing the two ways of allocating and freeing memory in a stack and a heap. Yum!

It's unordered. A "heap" of storage.

It isn't an ordered heap data structure.

I don't know if it is the first but ALGOL 68 had keyword 'heap' for allocating memory from the free memory heap.

The first use of 'heap' is likely to be found somewhere between 1958, when John McCarthy invented garbage collection for Lisp and the development of ALGOL 68

It's a large, tangled pile of disorganized junk, in which nothing can be found unless you know exactly where to look.

Just like java and javascript, heap (free store) and heap (data structure) are named such to insure that our fraternity is inpenetrable to outsiders, thus keeping our jobs secure.

I always figured it was kind of a clever way of describing it in comparison to the stack. The heap is like an overgrown, disorganized stack.

Heap usually has these features:

  1. You can't predict the address of a block malloc() returns.

  2. You have no idea of how the address returned by the next malloc() is related to the address of the previous one.

  3. You can malloc() blocks of variable sizes.

So you have something that can store a bunch of blocks of variable sizes and return them in some generally unpredictable order. How else would you call it if not "heap"?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!