Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to deallocate an array of pointers ?

Status
Not open for further replies.

Gilles

Programmer
Nov 24, 2000
5
ZA
In a dll I allocate memory for an array of char* :<br>ppChar = new char*[ y ];<br>When I try to free it I get an error :<br>delete [] ppChar;<br>What is my mistake ? Thank you.<br>
 
Dear Gilles,<br><br>&gt; When I try to free it I get an error <br><br>What is the error? This works in VC 6 without any errors:<br><br>char** pbuf = new char*[10];<br>delete [] pbuf;<br><br>-pete<br>
 
Thank you Pete,<br>Actually, my code looks more like :<br><br>short&nbsp;&nbsp;i;<br>char** pbuf = new char*[100];<br><br>for(i=0; i&lt;=100; i++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;pbuf<i> = new char[100];<br>}<br><br>for(i=0; i&lt;=100; i++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;delete [] pbuf<i>;<br>}<br>&nbsp;&nbsp;<br>delete [] pbuf;<br><br><br>This last line yields the following error :<br><br>Damage: after Normal block (#192) at 0x01BE0180<br><br>Thank you for your help.<br>Gilles<br>
 
Sorry, but i indexes don't appear in my previous <br>message as they are interpreted as italic signals.<br>Here is a new version :<br><br>Thank you Pete,<br>Actually, my code looks more like :<br><br>char** pbuf = new char*[100];<br>short&nbsp;&nbsp;k;<br><br>for(k=0; k&lt;100; k++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;pbuf[k] = new char[100];<br>}<br><br>for(k=0; k&lt;100; k++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;delete [] pbuf[k];<br>}<br>&nbsp;&nbsp;<br>delete [] pbuf;<br><br><br>This last line yields the following error :<br><br>Damage: after Normal block (#192) at 0x01BE0180<br><br>Thank you for your help.<br><br>Gilles<br>
 
My 2 cents - try changing new char*[] to new (char *)[]. I seem to remember reading somewhere that there was something dodgy about new with * and [].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top