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

2019-01-11 06:37发布

I am trying to find the official (or a good enough) reason that the free store is commonly referred to as the heap.

Except for the fact that it grows from the end of the data segment, I can't really think of a good reason, especially since it has very little to do with the heap data structure.

Note: Quite a few people mentioned that it's just a whole bunch of things that are kind of unorganized. But to me the term heap physically means a bunch of things that are physically dependent on one another. You pull one out from underneath, everything else collapses on it, etc. In other words, to me heap sounds loosely organized (e.g., latest things are on top). This is not exactly how a heap actually works on most computers, though if you put stuff towards the beginning of the heap and then grew it I guess it could work.

9条回答
We Are One
2楼-- · 2019-01-11 07:19

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?"

查看更多
做自己的国王
3楼-- · 2019-01-11 07:19

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

查看更多
祖国的老花朵
4楼-- · 2019-01-11 07:21

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.

查看更多
登录 后发表回答