{"id":4701,"date":"2014-03-30T14:45:56","date_gmt":"2014-03-30T14:45:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/operating-systems-memory-management-malloc-invocation-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:45:56","modified_gmt":"2014-03-30T14:45:56","slug":"operating-systems-memory-management-malloc-invocation-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/operating-systems-memory-management-malloc-invocation-collection-of-common-programming-errors\/","title":{"rendered":"operating systems memory management &#8211; malloc() invocation-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m studying up on OS memory management, and I wish to verify that I got the basic mechanism of allocation \\ virtual memory \\ paging straight.<\/p>\n<p>Let&#8217;s say a process calls malloc(), what happens behind the scenes? my answer: The runtime library finds an appropriately sized block of memory in its <strong>virtual<\/strong> memory address space. (This is where allocation algorithms such as <em>first-fit<\/em>, <em>best-fit<\/em> that deal with fragmentation come into play)<\/p>\n<p>Now let&#8217;s say the process accesses that memory, how is that done? my answer: The memory address, as seen by the process, is in fact virtual. The OS checks if that address is currently mapped to a physical memory address and if so performs the access. If it isn&#8217;t mapped &#8211; a page fault is raised.<\/p>\n<p>Am I getting this straight? i.e. the compiler\\runtime library are in charge of allocating virtual memory blocks, and the OS is in charge of a mapping between processes&#8217; virtual address and physical addresses (and the paging algorithm that entails)?<\/p>\n<p>Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m studying up on OS memory management, and I wish to verify that I got the basic mechanism of allocation \\ virtual memory \\ paging straight. Let&#8217;s say a process calls malloc(), what happens behind the scenes? my answer: The runtime library finds an appropriately sized block of memory in its virtual memory address space. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4701","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4701"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4701\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}