Partager via


The basics of basics

[Copied over from my original blog https://ssinghal.spaces.live.com to have everything under one roof] 

One of most basic component in SQLOS is memory object. Every introduction to memory object (refer https://blogs.msdn.com/slavao/archive/2005/02/11/371063.aspx) starts with the fact that "SQLOS's memory object is nothing but a heap". And then goes on to explain the how SQLOS supports three types of memory objects (fixed size, variable size, and incremental type) and how its related to another component in Sqlos space called memory clerk.

So far so good, but one thing that was slightly hazy was why do we need something like memory object (or heap) when we can use virtual memory functions to manage our VAS (virtual address space).

The short answer is that the granularity of smallest allocable chunk of memory using virtual memory management functions is 64K. So if you need to have a smaller granularity than that, heap is your answer. You can allocate any amount of memory even if it’s just a few handful of bytes and heap manager will satisfy that request (internally committing additional pages of memory as needed)

There is an old (but kind of relevant) article on MSDN that explains in detail the heap memory management in Win32 (https://msdn2.microsoft.com/en-us/library/ms810603.aspx)

Coming back to Sql Server and Sqlos, "memory objects are nothing but a heap" :-). But in addition to providing the allocation granularity, it also provides things like type of allocation (fixed/variable/incremental), debugging support, caching support or support for synchronization by wrapping existing memory object into a sort of proxy that has the required additional support.