Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.grandecom!news.posted.grandecom.POSTED!not-for-mail NNTP-Posting-Date: Fri, 13 Jan 2012 12:04:24 -0600 User-Agent: Microsoft-Entourage/12.23.0.091001 Date: Fri, 13 Jan 2012 12:04:22 -0600 Subject: Re: How to free this memory? From: Bint Newsgroups: comp.lang.c++ Message-ID: Thread-Topic: How to free this memory? Thread-Index: AczSHcbp9nd68JGpTUyUov/a4gNmiA== References: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Lines: 57 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 216.82.212.181 X-Trace: sv3-AHNyzkkyHFyeFUZFMmJfqOtUlYtyRrGEE1IrQ3xRV/pBs3ghS6torFb//udcfH2QxZUclZzyDJVbFm5!fImHX9EZY/0Ij8JyjBHtXNeWbpyfxIdf/KKqvluCailFIsKfyQ8yju9svhe+tGo= X-Complaints-To: abuse@grandecom.com X-DMCA-Complaints-To: abuse@grandecom.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2695 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:13345 > On 13/01/2012 17:37, Paul > "Bint" wrote in message news:CB35C06F.B997%bint@ign.com... >>> Hello, I am allocating some vertices to pass to a function, and then I >>> want >>> to free the memory. How do I do this? The compiler is giving me warnings >>> when I do it this way: >>> >>> trivertex **vertices; >>> >>> vertices = new trivertex*[2]; >>> >>> vertices[0] = new trivertex[100]; >>> vertices[1] = new trivertex[50]; >>> >>> . >>> . >>> . >>> delete vertices[0]; >>> delete vertices[1]; >>> delete vertices; >>> >>> I get this warning: >>> " 'delete' applied to a pointer-to-array type 'trivertex *' (aka 'double >>> (*)[3]') treated as delete" >>> >>> >>> Thanks! >>> B >> >> Hi >> >> You should use delete[] , to delete memory allocated with new []. >> So... >> delete[] veritces[0]; >> delete[] vertices[1]; >> delete[] vertices; > > Yes you do delete[] what you new[] however the poster should use > std::vector as Alf suggests; it is very rare that you need to use > dynamically allocated arrays these days. > > One use-case for dynamically allocated arrays is when you want a > dynamically sized *uninitialized* buffer. > > /Leigh I don't have any experience with namespaces or std:vector. I will try it and see if what Alf posted works in my code. But if delete[] works, then what is wrong with using it? Thanks B