{"id":5093,"date":"2013-03-01T07:00:00","date_gmt":"2013-03-01T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/03\/01\/the-source-of-much-confusion-backed-by-the-system-paging-file\/"},"modified":"2013-03-01T07:00:00","modified_gmt":"2013-03-01T07:00:00","slug":"the-source-of-much-confusion-backed-by-the-system-paging-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130301-00\/?p=5093","title":{"rendered":"The source of much confusion: &#8220;backed by the system paging file&#8221;"},"content":{"rendered":"<p>Perhaps one of the most misunderstood sentences in the Win32 documentation is this little bit in <a href=\"http:\/\/msdn.microsoft.com\/library\/aa366537(v=vs.85).aspx\"> the documentation for <code>Create&shy;File&shy;Mapping<\/code><\/a>:<\/p>\n<blockquote class=\"q\"><p> If <i>hFile<\/i> is <b>INVALID_HANDLE_VALUE<\/b>, the calling process must also specify a size for the file mapping object in the <i>dwMaximum&shy;Size&shy;High<\/i> and <i>dwMaximum&shy;Size&shy;Low<\/i> parameters. In this scenario, <b>Create&shy;File&shy;Mapping<\/b> creates a file mapping object of a specified size that is <u>backed by the system paging file instead of by a file in the file system<\/u>. <\/p><\/blockquote>\n<p> When people read the underlined portion, they interpret this to mean &#8220;The data in the file mapping object <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2009\/07\/06\/9818299.aspx#9829063\"> will be written to the system paging file<\/a>.&#8221; But that&#8217;s not what it says. It says that it is <i>backed by<\/i> the system paging file. In other words, &#8220;If I need to page this memory out, I will store it in the system paging file.&#8221; <\/p>\n<p> Note the word &#8220;if&#8221;. <\/p>\n<p> Usually, people get all worked up about the description because &#8220;I don&#8217;t want this data to be written to disk by the creator, and then read from the disk by the consumer. I want this to be stored in RAM, just like the memory I allocate with <code>Heap&shy;Allocate<\/code> or <code>Virtual&shy;Alloc<\/code>.&#8221; Of course, what they didn&#8217;t realize is that memory allocated with <code>Heap&shy;Allocate<\/code> and <code>Virtual&shy;Alloc<\/code> is <i>also<\/i> backed by the system paging file. If memory allocated by <code>Heap&shy;Allocate<\/code> and <code>Virtual&shy;Alloc<\/code> needs to be paged out, the memory manager will write it to the paging file. <\/p>\n<p> In other words, &#8220;backed by the system paging file&#8221; just means &#8220;handled like regular virtual memory.&#8221; <\/p>\n<p> If the memory is freed before it ever gets paged out, then it will never get written to the system paging file. Just like you wanted. <\/p>\n<p> The documentation was written with <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/05\/12\/10163578.aspx\"> kernel-colored glasses<\/a>. They figured that you knew that paging file-backed memory was just a way of saying &#8220;normal pageable memory.&#8221; <\/p>\n<p> <b>Exercise<\/b>: What happens if paging is disabled? Where is the memory backed if there is no paging file? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perhaps one of the most misunderstood sentences in the Win32 documentation is this little bit in the documentation for Create&shy;File&shy;Mapping: If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximum&shy;Size&shy;High and dwMaximum&shy;Size&shy;Low parameters. In this scenario, Create&shy;File&shy;Mapping creates a file mapping object of a specified [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-5093","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Perhaps one of the most misunderstood sentences in the Win32 documentation is this little bit in the documentation for Create&shy;File&shy;Mapping: If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximum&shy;Size&shy;High and dwMaximum&shy;Size&shy;Low parameters. In this scenario, Create&shy;File&shy;Mapping creates a file mapping object of a specified [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=5093"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5093\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=5093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=5093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=5093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}