<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Cascadia Mono";
panose-1:2 11 6 9 2 0 0 2 0 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:70.85pt 85.05pt 70.85pt 85.05pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="en-DE" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">After further investigation I found that the order in which the CMyClass instances are destroyed matter. delete[] destroys them in reverse
order while the vector destroys them in a forward order.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">I could emulate both ways by using placement new:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:gray">#include</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515"><cassert></span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:gray">#include</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515"><vector></span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">int</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> SINGLE_ALLOC_SIZE = 21200;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">int</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> NUMBER_OF_ALLOCS = 21200 * 4;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">class</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">public</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> CMyClass()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> lpData =
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">new</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">char</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">[SINGLE_ALLOC_SIZE];<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#6F008A">assert</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">(lpData);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> };<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> ~CMyClass()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">delete[]</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> lpData;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> };<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">public</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">char</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* lpData;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">};<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat1()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"strat1 start\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* lpList =
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">new</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">[NUMBER_OF_ALLOCS];<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"after alloc. starting freeing\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">delete[]</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> lpList;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"end\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat2()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"strat2 start\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> std::</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">vector</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">>
lpList(NUMBER_OF_ALLOCS);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"after alloc. starting freeing\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"end\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat3()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"strat3 start\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* block = malloc(NUMBER_OF_ALLOCS *
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">sizeof</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">));<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">for</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">size_t</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
i = 0; i < NUMBER_OF_ALLOCS; ++i)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* address = (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">char</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">*)block
+ i * </span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">sizeof</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">new</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> (address)
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"after alloc. starting freeing\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">for</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">size_t</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
i = 0; i < NUMBER_OF_ALLOCS; ++i)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* instance = (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">*)((</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">char</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">*)block
+ (NUMBER_OF_ALLOCS - i - 1) * </span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">sizeof</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">));<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> instance->~CMyClass();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> free(block);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"end\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat4()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"strat4 start\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* block = malloc(NUMBER_OF_ALLOCS *
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">sizeof</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">));<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">for</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">size_t</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
i = 0; i < NUMBER_OF_ALLOCS; ++i)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">void</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* address = (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">char</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">*)block
+ i * </span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">sizeof</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">new</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> (address)
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"after alloc. starting freeing\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">for</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">size_t</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
i = 0; i < NUMBER_OF_ALLOCS; ++i)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">* instance = (</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">*)((</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">char</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">*)block
+ i * </span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">sizeof</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#2B91AF">CMyClass</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">));<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> instance->~CMyClass();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> free(block);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> printf(</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:#A31515">"end\n"</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">int</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> main()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">do</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat1();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat2();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat3();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> strat4();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> }
</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:blue">while</span><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"> (1);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Cascadia Mono";color:black">}</span><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> gdal-dev <gdal-dev-bounces@lists.osgeo.org>
<b>On Behalf Of </b>Uhrig, Stefan via gdal-dev<br>
<b>Sent:</b> Thursday, March 21, 2024 2:17 PM<br>
<b>To:</b> gdal-dev@lists.osgeo.org<br>
<b>Subject:</b> Re: [gdal-dev] Experience with slowness of free() on Windows with lots of allocations?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">I was curious and gave it a try. I also saw the bad performance on deallocations, but surprisingly the usage of a std::vector in the
outer loop speeds things up considerably.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">I could still see a peak memory usage of 1.8GiB, so it does not seem as if the compiler did optimize something out.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><snip><o:p></o:p></span></p>
</div>
</body>
</html>