O'Reilly logo

Shared Source CLI Essentials by Ted Neward, Geoff Shilling, David Stutz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Organizing and Allocating Dynamic Memory

The choice of a discipline for component memory allocation is deeply tied to component lifetimes. Control structures, such as the CLI’s threads and application domains, offer simple and efficient disciplines for managing component lifetimes and memory and, as we have seen, are used by the CLI as locations for storing both static and stack-based information. As already pointed out, however, storage strategies based on these mechanisms will work onlywhen the lifetimes of the components and resources being allocated are in sync with the lifetimes of the control structures. There are many cases when this is not the case. There are also many times when storing large amounts of data in runtime control structures might cause resource exhaustion problems or bad locality of reference.

Heaps, of course, solve these problems by using regions of memory that are managed by allocating subblocks to clients and tracking these so that the clients can later release their subblocks in arbitrary order, at any time. When used manually, a programmer “checks out” subblocks of heap memory with a function like malloc, holds them as long as necessary, and then frees them explicitly, which makes the memory available for recycling. Heaps that are managed using garbage collection, on the other hand, permit clients to release their subblocks by simply abandoning references to them. When quantities of heap memory run low, the garbage collection service can take ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required