{"id":16997,"date":"2024-03-07T15:21:07","date_gmt":"2024-03-07T15:21:07","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=16997"},"modified":"2024-03-10T12:44:32","modified_gmt":"2024-03-10T12:44:32","slug":"stddeque-g-implementation-details","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=16997","title":{"rendered":"Layout of std:deque (libstdc++)"},"content":{"rendered":"<p><strong>Layout<\/strong><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.max-sperling.bplaced.net\/wp-content\/uploads\/2017\/06\/Deque.png\" class=\"aligncenter\" \/><\/p>\n<ul>\n<li>The meta element on the stack consumes 10 words (80 Byte on x64, 40 Byte on x86).<\/li>\n<li>Each chunk on the heap has a size of 512 Byte<sup>1<\/sup> if sizeof(val) <= 256 Byte, else sizeof(val).<\/li>\n<li>The number of the chunks and those the size of the map depends on the amount of values.<\/li>\n<\/ul>\n<p><sup>1<\/sup> <a href=\"https:\/\/github.com\/gcc-mirror\/gcc\/blob\/c891d8dc23e1a46ad9f3e757d09e57b500d40044\/libstdc%2B%2B-v3\/include\/bits\/stl_deque.h#L92\">gcc\/libstdc++-v3\/include\/bits\/stl_deque.h<\/a><\/p>\n<hr>\n<p><strong>Example<\/strong><\/p>\n<pre class=\"brush: cpp; title: main.cpp; notranslate\" title=\"main.cpp\">\r\n#include &lt;deque&gt;\r\n\r\nint main()\r\n{\r\n    std::deque&lt;int&gt; deq = { 1, 2, 3, 4, 5 };\r\n    return 0;\r\n}\r\n<\/pre>\n<pre>\r\n$ g++ --version\r\ng++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0\r\n$ g++ main.cpp -g\r\n$ gdb a.out\r\n(gdb) b 6\r\n(gdb) r\r\n(gdb) disable pretty-printer\r\n(gdb) p \/x deq\r\n$1 = {...\r\n  _M_impl = {...\r\n             _M_map = 0x55555556c2b0,\r\n             _M_map_size = 0x8,\r\n             _M_start = {_M_cur = 0x55555556c300,\r\n                         _M_first = 0x55555556c300,\r\n                         _M_last = 0x55555556c500,\r\n                         _M_node = 0x55555556c2c8}, \r\n             _M_finish = {_M_cur = 0x55555556c314,\r\n                          _M_first = 0x55555556c300,\r\n                          _M_last = 0x55555556c500,\r\n                          _M_node = 0x55555556c2c8}} ...}\r\n(gdb) p sizeof(deq)\r\n$1 = 80\r\n(gdb) x\/8g deq._M_impl._M_map\r\n0x55555556c2b0:\t0x0000000000000000 0x0000000000000000\r\n0x55555556c2c0:\t0x0000000000000000 0x000055555556c300\r\n0x55555556c2d0:\t0x0000000000000000 0x0000000000000000\r\n0x55555556c2e0:\t0x0000000000000000 0x0000000000000000\r\n(gdb) x\/5w 0x000055555556c300\r\n0x55555556c300:\t0x00000001\t0x00000002\t0x00000003\t0x00000004\r\n0x55555556c310:\t0x00000005\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Layout The meta element on the stack consumes 10 words (80 Byte on x64, 40 Byte on x86). Each chunk<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[80,28],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16997"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16997"}],"version-history":[{"count":12,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16997\/revisions"}],"predecessor-version":[{"id":17043,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16997\/revisions\/17043"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16997"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}