🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13806

Re: using of delete for **arrays: double** C = new double* [azei]:???????????????????

#13806
From: JD
Date: Tue, 16 Sep 2003 14:33
37 lines
1961 bytes
"Peter Jahn" <pjahn@uni-kassel.de> wrote:
> [...] but Idon'nt knw how to delete C:

You also don't know how to allocate it.

C is defined as a pointer to pointers of type double but you
incorrectly allocate each eliment.

>    double** C = new double* [azei];
>    for (int i = 0;i<=azei;i++)
>      {
>      C[i] = new double[bsp];

This allocates bsp count doubles. The line should read:

       C[i] = new double;

To correctly delete C, since you used 2 new statements, you
need 2 delete statements and since one of the new statements
used brackets ( [] ), one of the deletes needs to also use the
brackets:

    for( int x = 0; x <= azei; ++x ) delete C[ x ];
    delete [] C;

> after calling this routine in the main program I have to
> delete array C before I can use the routine again. but how
> to do this???

Your basic steps should be:

    Allocate C
    Use C
    Delete C when finished using it

~ JD
Technical Details
Message-ID: <3f671f3a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <bk72pv$pgse7$1@uni-berlin.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,6989430920349a4
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-09-16 07:41:21 PST
From: "JD" <nospam@nospam.com>
Sender: "JD" <nospam@nospam.com>
Reply-To: "JD" <nospam@nospam.com>
Subject: Re: using of     delete    for **arrays:                              double** C = new double* [azei]:???????????????????
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 172.145.87.57 172.145.87.57    
References:  <bk72pv$pgse7$1@uni-berlin.de>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3f671f3a$1@newsgroups.borland.com>
Date: 16 Sep 2003 07:33:30 -0700
X-Trace: newsgroups.borland.com 1063722810 207.105.83.65 (16 Sep 2003 07:33:30 -0700)
Lines: 38
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail