{"id":434,"date":"2009-10-12T20:25:21","date_gmt":"2009-10-13T01:25:21","guid":{"rendered":"http:\/\/vgable.com\/blog\/?p=434"},"modified":"2009-11-25T12:16:44","modified_gmt":"2009-11-25T17:16:44","slug":"dont-check-malloc","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2009\/10\/12\/dont-check-malloc\/","title":{"rendered":"Don&#8217;t Check malloc()"},"content":{"rendered":"<blockquote><p>There&#8217;s no point in trying to recover from a <code>malloc<\/code> failure on OS X, because by the time you detect the failure and try to recover, your process is likely to already be doomed. There&#8217;s no need to do your own logging, because <code>malloc<\/code> itself does a good job of that. And finally there&#8217;s no real need to even explicitly abort, because any <code>malloc<\/code> failure is virtually guaranteed to result in an instantaneous crash with a good stack trace.<\/p><\/blockquote>\n<p>&#8212;<a href=\"http:\/\/www.mikeash.com\/?page=pyblog\/friday-qa-2009-10-09-defensive-programming.html\">Mike Ash<\/a><\/p>\n<p>This is <em>excellent advice<\/em>. Peppering your code with <code>if<\/code> statements harms readability and simplicity.<\/p>\n<p>It&#8217;s still a good idea to check large (many MB) <code>malloc<\/code>s, but I can&#8217;t imagine recovering gracefully from a situation where 32 byte memory allocations are failing on a modern desktop.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s no point in trying to recover from a malloc failure on OS X, because by the time you detect the failure and try to recover, your process is likely to already be doomed. There&#8217;s no need to do your own logging, because malloc itself does a good job of that. And finally there&#8217;s no [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6,203,3,5,4,24,10],"tags":[613,77,496,497],"class_list":["post-434","post","type-post","status-publish","format-standard","hentry","category-c","category-cocoa","category-iphone","category-macosx","category-objective-c","category-programming","category-quotes","category-tips","tag-c","tag-debugging","tag-malloc","tag-mike-ash"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=434"}],"version-history":[{"count":7,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/434\/revisions"}],"predecessor-version":[{"id":512,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/434\/revisions\/512"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}