30.06.2013 Views

Under the Hood of .NET Memory Management - Simple Talk

Under the Hood of .NET Memory Management - Simple Talk

Under the Hood of .NET Memory Management - Simple Talk

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7: The Windows <strong>Memory</strong> Model<br />

The L3 cache is stored on <strong>the</strong> mo<strong>the</strong>rboard and is <strong>the</strong> largest cache store; for example, <strong>the</strong><br />

Intel Core I7 processor has an 8 MB L3 cache. It's <strong>the</strong> slowest <strong>of</strong> all three caches, but still<br />

faster than direct memory access.<br />

When a memory address is requested, <strong>the</strong> caches are checked first, before an attempt is<br />

made to access physical RAM, and <strong>the</strong> OS only actually has to deal with <strong>the</strong> paging file at<br />

<strong>the</strong> end <strong>of</strong> that checking sequence.<br />

The access order is L1–>L2–>L3–>physical memory–>page file.<br />

The intricacies <strong>of</strong> <strong>the</strong> data cache could fill a whole new chapter in <strong>the</strong>mselves, but we'll<br />

not go <strong>the</strong>re in this book, as I think we've covered enough for now.<br />

The Long and Winding Road<br />

We've gone from an allocation and garbage collection in .<strong>NET</strong>, right through object<br />

retention and promotion, and on to subsequent allocation <strong>of</strong> ephemeral segments.<br />

Beyond segments, we looked at how VirtualAlloc is used to create ephemeral<br />

segments, what VirtualAlloc actually does, and what it translates to. Finally, we've<br />

broken memory allocation down into its raw representation within <strong>the</strong> OS, and analyzed<br />

how huge Virtual Address Spaces are managed to give processes access to resources far in<br />

excess <strong>of</strong> <strong>the</strong>ir machine's physical memory limitations.<br />

Summary<br />

Maybe you're wondering why you needed to know all this. Well, I suppose <strong>the</strong> short<br />

answer is because what happens beyond <strong>the</strong> .<strong>NET</strong> boundary is no longer a mystery.<br />

.<strong>NET</strong> is built on top <strong>of</strong> <strong>the</strong> Windows API, and so its impacts and limitations come from<br />

<strong>the</strong>re as well.<br />

212

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!