{"id":4131,"date":"2014-03-30T08:01:21","date_gmt":"2014-03-30T08:01:21","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/is-there-any-guarantee-of-alignment-of-address-return-by-cs-new-operation-collection-of-common-programming-errors\/"},"modified":"2014-03-30T08:01:21","modified_gmt":"2014-03-30T08:01:21","slug":"is-there-any-guarantee-of-alignment-of-address-return-by-cs-new-operation-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/is-there-any-guarantee-of-alignment-of-address-return-by-cs-new-operation-collection-of-common-programming-errors\/","title":{"rendered":"Is there any guarantee of alignment of address return by C++&#39;s new operation?-Collection of common programming errors"},"content":{"rendered":"<p>Most of experienced programmer knows data alignment is important for program&#8217;s performance. I have seen some programmer wrote program that allocate bigger size of buffer than they need, and use the aligned pointer as begin. I am wondering should I do that in my program, I have no idea is there any guarantee of alignment of address returned by C++&#8217;s new operation. So I wrote a little program to test<\/p>\n<pre><code>for(size_t i = 0; i &lt; 100; ++i) {\n    char *p = new char[123];\n    if(reinterpret_cast(p) % 4) {\n        cout<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Most of experienced programmer knows data alignment is important for program&#8217;s performance. I have seen some programmer wrote program that allocate bigger size of buffer than they need, and use the aligned pointer as begin. I am wondering should I do that in my program, I have no idea is there any guarantee of alignment [&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-4131","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4131","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=4131"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4131\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}