delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/07/12:10:53

From: apsh AT ecr DOT mu DOT oz DOT au (Alistair_P SHILTON)
Newsgroups: comp.os.msdos.djgpp
Subject: Strange behaviour of new/delete
Date: 7 Jun 2000 05:50:10 GMT
Organization: Computer Science, University of Melbourne
Lines: 59
Message-ID: <8hknqj$gki$1@mulga.cs.mu.OZ.AU>
NNTP-Posting-Host: gromit.ecr.mu.oz.au
X-Trace: mulga.cs.mu.OZ.AU 960357011 17042 128.250.61.61 (7 Jun 2000 05:50:10 GMT)
X-Complaints-To: usenet AT cs DOT mu DOT OZ DOT AU
NNTP-Posting-Date: 7 Jun 2000 05:50:10 GMT
X-Newsreader: TIN [version 1.2 PL2]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I was wondering if anyone else has encountered trouble with new/delete.
I have a function which allocates memory with new as follows:

    double **res;

    res = new double *[3];

    if ( res == NULL ) { return NULL; }

    a = new double[i];
    if ( a == NULL ) { return NULL; }

    b = new double[1];
    if ( b == NULL ) { return NULL; }

    c = new double[size-i+1];
    if ( c == NULL ) { return NULL; }

    res[0] = a;
    res[1] = b;
    res[2] = c;

For simplicity, I've allocated 1 double too much to a and c.  Later on I delete
as follows:

(res has since become removal)

        delete removal[0];
printf("0 down\n");
        delete removal[1];
printf("1 down\n");
        delete removal[2];
printf("2 down\n");

printf("freed partial removal\n");
        delete removal;

printf("free mem\n");

(ignore the printf's - I was debugging).  The odd behaviour is this - if I 
don't actually use a or c (don't put anything in them), then it hangs at 
delete removal[2] (even though a non zero amount of memory was allocated)!!

I've checked on unix, and it works fine - so is this a known bug with djgpp,
or am I missing something?




----------------------------------------------------

Thanks

Alistair Shilton

http://www.ee.mu.oz.au/pgrad/apsh



- Raw text -


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