delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/23/11:33:30

From: "Aleksey Kondratyev" <akondra AT no-spam-mv DOT ru>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Deleting mem allocated to dynamic array?
Date: Tue, 23 Jun 1998 14:41:46 +0400
Organization: Middle Volga Communication service
Lines: 31
Message-ID: <6mo1mv$gsk$1@simtel.ru>
References: <6mmd9s$o7f AT bgtnsc03 DOT worldnet DOT att DOT net> <358EFF0A DOT 3800AC93 AT ipass DOT net>
Reply-To: "Aleksey Kondratyev" <djgpp AT delorie DOT com>
NNTP-Posting-Host: ppp13.usr.mv.ru
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>Should be something like:
>
>   for (i=0;i<XSize; i++)
>        delete Tiles[i];
>   delete Tiles;

Never do it! Modern C++ has new[] and delete[] operators especially
for arrays. The right form will be

for (i=0;i<XSize; i++)
       delete [] Tiles[i];
  delete [] Tiles;

Note that operator new[] (it is invoked for an array allocation) can use
other heap format (perhaps, other heap on some platforms). For example
new[] would allocate additional memory to store a number of array elements
for the sake of providing information on an array size to delete[] operator.
if you do something like 'char *a=new char[10]' and try 'delete a', it would
cause run-time heap corruption errors.

----------------------------------------------------------------------
Aleksey Kondratyev
Ph.D. student of Ulyanovsk state University, Russia
http://www.mv.ru/~akondra
E-mail akondra AT mmf DOT univ DOT simbirsk DOT su
           akondra AT mv DOT ru
If the  address above contains no-spam-, please,
remove it when replying.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019