Article View: borland.public.cppbuilder.migration
Article #55Re: newbie question
From: Alisdair Meredith [TeamB]
Date: Fri, 15 Oct 2004 10:55
Date: Fri, 15 Oct 2004 10:55
45 lines
2021 bytes
2021 bytes
Colin B Maharaj wrote: > If you are using the heap, then you will use a pointer instead . > The code will look like this.... > > char *s = new char [80]; > > or > > char *s; > s = new char [80]; > > WARNING WARNING WARNING...... > > Whenever you use memory from the heap you must manually give it back > to the operating system like this..... > > delete s; > > If not you get a memory leak and could mess up windows. > > remember for every new you must have a corresponding delete. More important! If you allocate an array using the array form of new [], you must return that memory with the array form of delete []. i.e. char *s = new char [80]; delete [] s; You get undefined behaviour if you call delete on an array allocated with new[]. I know MS choose to define the behaviour as being smart for you, so you don't even notice the bug. I believe that with Borland you are probably corrupting the memory manager, which will give subtle and strange bugs in a totally different part of your application at some point in the future. Other than that, good advice <g> AlisdairM(TeamB)
Technical Details
Message-ID:
<416faca0@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40f54305@newsgroups.borland.com> <4158b283@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 110f51,43afb45cd865d8f5 X-Google-Attributes: gid110f51,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Alisdair Meredith [TeamB]" <alisdair.NO.SPAM.PLEASE.meredith@uk.renaultf1.com> Subject: Re: newbie question Newsgroups: borland.public.cppbuilder.migration References: <40f54305@newsgroups.borland.com> <4158b283@newsgroups.borland.com> Organization: Renault F1 Team Ltd. User-Agent: XanaNews/1.16.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 195.153.139.2 Message-ID: <416faca0@newsgroups.borland.com> Date: 15 Oct 2004 03:55:28 -0700 X-Trace: newsgroups.borland.com 1097837728 195.153.139.2 (15 Oct 2004 03:55:28 -0700) Lines: 45 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail