{"id":111,"date":"2009-07-09T22:01:00","date_gmt":"2009-07-09T22:01:00","guid":{"rendered":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/"},"modified":"2009-07-09T22:01:00","modified_gmt":"2009-07-09T22:01:00","slug":"vector-of-pointers-crashes-on-delete","status":"publish","type":"post","link":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/","title":{"rendered":"Vector of pointers crashes on delete"},"content":{"rendered":"<p>I have a java gui which calls a C++ dll which in turn calls another C++ dll. Both dlls are built using Microsoft Visual C++ 6.0;<br \/>Both dlls contain functions which take in 4 vectors. The first dll function calls the second dll function. <br \/>The first 2 vectors are source parameters and the last 2 are result vectors. All vectors contain the same number elements.<br \/>The function call in the first dll looks something like this:<\/p>\n<p>convert(std::vector<classA*>&#038; firstVector, std::vector<class1*>&#038; secondVector, std::vector<class1*>&#038; thirdVector, std::vector<classA*>&#038; fourthVector)<br \/>{<br \/>  thirdVector.reserve(10);<br \/>  fourthVector.reserve(10);<\/p>\n<p>  C2DLL* c2dll = new c2dll();<br \/>  c2dll->convert(firstVector, secondVector, thirdVector, fourthVector);<\/p>\n<p>.<br \/>.<br \/>.<br \/>.<br \/>.<br \/>.<br \/>.<\/p>\n<p>  for(int i = 0; i < 10; i++)<br \/>  {<br \/>    delete firstVector[i];<br \/>  }<br \/>  firstVector.clear();<\/p>\n<p>  for(int i = 0; i < 10; i++)<br \/>  {<br \/>    delete secondVector[i];<br \/>  }<br \/>  secondVector.clear();<\/p>\n<p>  for(int i = 0; i < 10; i++)<br \/>  {<br \/>    delete thirdVector[i];<br \/>  }<br \/>  thirdVector.clear();<\/p>\n<p>  for(int i = 0; i < 10; i++)<br \/>  {<br \/>    delete fourthVector[i];<br \/>  }<br \/>  fourthVector.clear();<br \/>}<\/p>\n<p>void C2DLL::convert(std::vector<classA*>&#038; firstVector, std::vector<class1*>&#038; secondVector, std::vector<class1*>&#038; thirdVector, std::vector<classA*>&#038; fourthVector)<br \/>{<br \/>  for(int i = 0; i < 10; i++)<br \/>  {<br \/>    thirdVector.push_back(new Class2());  \/\/\/ Class2 is a subclass of Class1<br \/>    fourthVector.push_back(new ClassA());<br \/>  }<br \/>}<\/p>\n<p>Everything was running great until I would get to deleting each element of the fourthVector. The application would crash. For the life of me I could not figure out why. I finally did some Google searching and figured out it was the compiler settings.<br \/>Each dll needs to be built with the \/MD option. To set this, go to the project settings, C\/C++ tab, Code Generation Category. Select Debug Multithreaded DLL. <br \/>Apparently this allocates the memory used in each dll on the local heap. Before changing this setting, I was using Debug Mutithreaded. Since the memory for the fourth vector was allocated in the second C++ dll, the memory was not on the local heap for the first dll, which was where the memory was being deallocated.<br \/>C++ Memory, what a pain in the butt. <\/p>\n<p><a href=\"http:\/\/www.amazon.com\/gp\/redirect.html?ie=UTF8&amp;location=https%3A%2F%2Fwww.amazon.com%2Fs%3Fie%3DUTF8%26x%3D15%26ref%255F%3Dnb%255Fss%255Fb%26y%3D20%26field-keywords%3DC%252B%252B%26url%3Dsearch-alias%253Dstripbooks&amp;tag=extcas-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=390957\" target=\"_blank\" rel=\"noopener\">More C++<\/a><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a java gui which calls a C++ dll which in turn calls another C++ dll. Both dlls are built using Microsoft Visual C++ 6.0;Both dlls contain functions which take in 4 vectors. The first dll function calls the second dll function. The first 2 vectors are source parameters and the last 2 are [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[244,242,245,243],"tags":[],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-c-dll","category-microsoft-visual-c-6-0","category-pass-vector-of-pointers-to-function","category-vector-of-pointers-crashes-on-delete"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Vector of pointers crashes on delete - Zofxare Blog Home<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Vector of pointers crashes on delete - Zofxare Blog Home\" \/>\n<meta property=\"og:description\" content=\"I have a java gui which calls a C++ dll which in turn calls another C++ dll. Both dlls are built using Microsoft Visual C++ 6.0;Both dlls contain functions which take in 4 vectors. The first dll function calls the second dll function. The first 2 vectors are source parameters and the last 2 are [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/\" \/>\n<meta property=\"og:site_name\" content=\"Zofxare Blog Home\" \/>\n<meta property=\"article:published_time\" content=\"2009-07-09T22:01:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1\" \/>\n<meta name=\"author\" content=\"zofxare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"zofxare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/\"},\"author\":{\"name\":\"zofxare\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\"},\"headline\":\"Vector of pointers crashes on delete\",\"datePublished\":\"2009-07-09T22:01:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/\"},\"wordCount\":324,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\",\"articleSection\":[\"C++ dll\",\"Microsoft Visual C++ 6.0\",\"Pass vector of pointers to function\",\"Vector of pointers crashes on delete\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/\",\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/\",\"name\":\"Vector of pointers crashes on delete - Zofxare Blog Home\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\",\"datePublished\":\"2009-07-09T22:01:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\",\"contentUrl\":\"https:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2009\\\/07\\\/09\\\/vector-of-pointers-crashes-on-delete\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vector of pointers crashes on delete\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/\",\"name\":\"Zofxare Blog Home\",\"description\":\"The Zofxare blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\",\"name\":\"zofxare\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"caption\":\"zofxare\"},\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/author\\\/zofxare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Vector of pointers crashes on delete - Zofxare Blog Home","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/","og_locale":"en_US","og_type":"article","og_title":"Vector of pointers crashes on delete - Zofxare Blog Home","og_description":"I have a java gui which calls a C++ dll which in turn calls another C++ dll. Both dlls are built using Microsoft Visual C++ 6.0;Both dlls contain functions which take in 4 vectors. The first dll function calls the second dll function. The first 2 vectors are source parameters and the last 2 are [&hellip;]","og_url":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/","og_site_name":"Zofxare Blog Home","article_published_time":"2009-07-09T22:01:00+00:00","og_image":[{"url":"https:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","type":"","width":"","height":""}],"author":"zofxare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"zofxare","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#article","isPartOf":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/"},"author":{"name":"zofxare","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce"},"headline":"Vector of pointers crashes on delete","datePublished":"2009-07-09T22:01:00+00:00","mainEntityOfPage":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/"},"wordCount":324,"commentCount":0,"image":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#primaryimage"},"thumbnailUrl":"https:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","articleSection":["C++ dll","Microsoft Visual C++ 6.0","Pass vector of pointers to function","Vector of pointers crashes on delete"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/","url":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/","name":"Vector of pointers crashes on delete - Zofxare Blog Home","isPartOf":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#primaryimage"},"image":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#primaryimage"},"thumbnailUrl":"https:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","datePublished":"2009-07-09T22:01:00+00:00","author":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce"},"breadcrumb":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#primaryimage","url":"https:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","contentUrl":"https:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1"},{"@type":"BreadcrumbList","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2009\/07\/09\/vector-of-pointers-crashes-on-delete\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zofxare.com\/zofxare\/blog\/"},{"@type":"ListItem","position":2,"name":"Vector of pointers crashes on delete"}]},{"@type":"WebSite","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#website","url":"https:\/\/zofxare.com\/zofxare\/blog\/","name":"Zofxare Blog Home","description":"The Zofxare blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zofxare.com\/zofxare\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce","name":"zofxare","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","caption":"zofxare"},"url":"https:\/\/zofxare.com\/zofxare\/blog\/author\/zofxare\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":0,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"wp:attachment":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}