{"id":1135,"date":"2006-04-25T19:40:01","date_gmt":"2006-04-25T10:40:01","guid":{"rendered":"http:\/\/yasu2.prosou.nu\/blog\/index.php\/2006\/04\/25\/malloc\/"},"modified":"2006-04-25T19:40:01","modified_gmt":"2006-04-25T10:40:01","slug":"malloc","status":"publish","type":"post","link":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/2006\/04\/25\/1135\/","title":{"rendered":"malloc \u305d\u306e\u5f8c"},"content":{"rendered":"<p>2GB \u4ee5\u4e0a\u3060\u3081\u306a\u306e\u3063\u3066\u300132bit \u7b26\u53f7\u4ed8\u304d\u306a\u5024\u3067\u30b5\u30a4\u30ba\u6307\u5b9a\u3057\u3066\u308b\u304b\u3089\u305d\u308c\u4ee5\u4e0a\u306f\u4e00\u6c17\u306b\u3068\u308c\u306a\u3044\u3060\u3051\u3058\u3083\u306d\uff1f\u3057\u304b\u3082\u3055\u3063\u304d\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3001free() \u3057\u3066\u306a\u3044\u3058\u3083\u3093\u3001\u3068\u3044\u3046\u3053\u3068\u306b\u6c17\u3065\u3044\u305f\u306e\u3067\u3001\u3084\u3063\u3066\u307f\u305f\u3002<br \/>\nFreeBSD \u306f\u307e\u3042\u3001loader.conf \u3067\u8a2d\u5b9a\u3057\u3066\u308b\u304b\u3089\u59a5\u5f53\u3002<\/p>\n<pre>\n% .\/a.out\nmalloc   128MB :OK!\nmalloc   256MB :OK!\nmalloc   384MB :OK!\nmalloc   512MB :OK!\nmalloc   640MB :OK!\nmalloc   768MB :OK!\nmalloc   896MB :OK!\nmalloc  1024MB :OK!\nmalloc  1152MB :OK!\nmalloc  1280MB :OK!\nmalloc  1408MB :OK!\nmalloc  1536MB :OK!\nmalloc  1664MB :OK!\nmalloc  1792MB :OK!\nmalloc  1920MB :OK!\nmalloc  2048MB :failed...\n<\/pre>\n<p>MacOS X \u306f 32bit \u74b0\u5883\u3067\u3082\u3051\u3063\u3053\u3046\u3044\u3051\u308b\u300264bit \u74b0\u5883\u306a\u3089\u7121\u9650\u3060\u3002<\/p>\n<pre>\n% .\/a.out\nmalloc   128MB :OK!\nmalloc   256MB :OK!\nmalloc   384MB :OK!\nmalloc   512MB :OK!\nmalloc   640MB :OK!\nmalloc   768MB :OK!\nmalloc   896MB :OK!\nmalloc  1024MB :OK!\nmalloc  1152MB :OK!\nmalloc  1280MB :OK!\nmalloc  1408MB :OK!\nmalloc  1536MB :OK!\nmalloc  1664MB :OK!\nmalloc  1792MB :OK!\nmalloc  1920MB :OK!\nmalloc  2048MB :OK!\nmalloc  2176MB :OK!\nmalloc  2304MB :OK!\nmalloc  2432MB :OK!\nmalloc  2560MB :OK!\nmalloc  2688MB :OK!\nmalloc  2816MB :OK!\nmalloc  2944MB :OK!\nmalloc  3072MB :OK!\nmalloc  3200MB :OK!\na.out(2293) malloc: *** vm_allocate(size=134217728) failed (error code=3)\na.out(2293) malloc: *** error: can't allocate region\na.out(2293) malloc: *** set a breakpoint in szone_error to debug\nmalloc  3328MB :failed...\n<\/pre>\n<p>\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre>\n#include &lt;stdio.h&gt;\n#include &lt;unistd.h&gt;\n#include &lt;stdlib.h&gt;\n#define UNIT 128\n#define LIMIT 10240\/UNIT \/\/ 10240\/UNIT = max 10GB\nvoid hogealloc(int level){\nvoid *p;\nint l;\nl = level + 1;\nprintf(\"malloc %5dMB :\", l*UNIT);\nif ( (p = malloc(UNIT*1024*1024)) == NULL ){\nprintf(\"failed...\\n\");\nreturn;\n} else {\nprintf(\"OK!\\n\");\nif( l == LIMIT ) printf(\"exit.\\n\");\nelse hogealloc(l);\nreturn;\n}\n}\nmain(){\nint s=1;\nhogealloc(0);\n}\n<\/pre>\n<p>free() \u3057\u3066\u306a\u3044\u3051\u3069\u3001\u307e\u3042\u3001\u3053\u308c\u306a\u3089\u3044\u3044\u3060\u308d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2GB \u4ee5\u4e0a\u3060\u3081\u306a\u306e\u3063\u3066\u300132bit \u7b26\u53f7\u4ed8\u304d\u306a\u5024\u3067\u30b5\u30a4\u30ba\u6307\u5b9a\u3057\u3066\u308b\u304b\u3089\u305d\u308c\u4ee5\u4e0a\u306f\u4e00\u6c17\u306b\u3068\u308c\u306a\u3044\u3060\u3051\u3058\u3083\u306d\uff1f\u3057\u304b\u3082\u3055\u3063\u304d\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3001free() \u3057\u3066\u306a\u3044\u3058\u3083\u3093\u3001\u3068\u3044\u3046\u3053\u3068\u306b\u6c17\u3065\u3044\u305f\u306e\u3067\u3001\u3084\u3063\u3066\u307f\u305f\u3002 FreeBSD  &hellip; <a href=\"https:\/\/yasu2.prosou.nu\/blog\/index.php\/2006\/04\/25\/1135\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;malloc \u305d\u306e\u5f8c&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-1135","post","type-post","status-publish","format-standard","hentry","category-unix-"],"_links":{"self":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1135"}],"version-history":[{"count":0,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1135\/revisions"}],"wp:attachment":[{"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yasu2.prosou.nu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}