{"id":19353,"date":"2009-01-28T10:00:00","date_gmt":"2009-01-28T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/01\/28\/when-you-have-only-16kb-of-memory-you-cant-afford-to-waste-any-of-it-on-fluffy-stuff\/"},"modified":"2009-01-28T10:00:00","modified_gmt":"2009-01-28T10:00:00","slug":"when-you-have-only-16kb-of-memory-you-cant-afford-to-waste-any-of-it-on-fluffy-stuff","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090128-00\/?p=19353","title":{"rendered":"When you have only 16KB of memory, you can&#8217;t afford to waste any of it on fluffy stuff"},"content":{"rendered":"<p><P>\nThe original IBM PC came with 16KB of memory.\n<\/P>\n<P>\nThat&#8217;s not a lot of space in which to squeeze an operating system,\nespecially since you had to leave enough memory for the user\nto actually <I>get work done<\/I>.\nA product of its time,\nthe MS-DOS kernel is written entirely in assembly language,\npretty much standard procedure for programs of the era.\nIt also meant that the code takes all sorts of crazy shortcuts\nto shave a few bytes here, a few bytes there,\nin order to squeeze into as little memory as possible.\nFor example, one very common trick was to have jump into\nthe middle of an instruction,\nknowing that the second half of the instruction,\nwhen reinterpreted as the start of an instruction,\nperforms the operation you wanted.\n<\/P>\n<P>\nAnyway, this subject arose in response to my discussion of\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/01\/30\/519388.aspx\">\nwhy a corrupted program sometimes results in a &#8220;Program too big to fit\nin memory&#8221; error<\/A>,\nwhich prompted the question from commenter 8 wondering\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/01\/30\/519388.aspx#519467\">\nwhy the kernel didn&#8217;t simply reject .COM files bigger\nthan 64KB<\/A>?\n<\/P>\n<P>\nWell, yeah, and that&#8217;s what it did: By complaining that it was too big\nto fit into memory.\nThere&#8217;s no point adding a redundant test.\n(It appears that some people like to call these redundant tests\n<I>\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/01\/30\/519388.aspx#519626\">\nbasic sanity checking<\/A><\/I>, but I consider sanity checking to be\nprotecting against unreasonable values before they cause trouble.\nBut in this case, they don&#8217;t cause trouble&mdash;the error is\ndetected and reported even without the so-called sanity check.)\n<\/P>\n<P>\nConsider:\n<\/P>\n<PRE>\nbool SomeFunction(&#8230;)\n{\n &#8230;\n if (x == 3) return false;\n if (x &lt; 10) return false;\n &#8230;\n}\n<\/PRE>\n<P>\nThe first test is redundant, because if <CODE>x<\/CODE> is three,\nthen even without the test, the function will still fail\nbecause <CODE>x<\/CODE> is also less than ten.\n<\/P>\n<P>\nAnd when you&#8217;re trying to squeeze your kernel into a few bytes as possible,\nyou&#8217;re certainly not going to waste your time coding up a redundant test.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The original IBM PC came with 16KB of memory. That&#8217;s not a lot of space in which to squeeze an operating system, especially since you had to leave enough memory for the user to actually get work done. A product of its time, the MS-DOS kernel is written entirely in assembly language, pretty much standard [&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":[2],"class_list":["post-19353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>The original IBM PC came with 16KB of memory. That&#8217;s not a lot of space in which to squeeze an operating system, especially since you had to leave enough memory for the user to actually get work done. A product of its time, the MS-DOS kernel is written entirely in assembly language, pretty much standard [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19353","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=19353"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19353\/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=19353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=19353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=19353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}