Thread View: gnu.g++.bug
2 messages
2 total messages
Started by "Naoki Saito Ext. 5471", GEO-002
Tue, 30 May 1989 21:16
new and delete bug report 2
Author: "Naoki Saito Ext. 5471", GEO-002
Date: Tue, 30 May 1989 21:16
Date: Tue, 30 May 1989 21:16
97 lines
2598 bytes
2598 bytes
Hi, everyone! There's a bug in new and delete in g++-1.34.2 on Sun3
OS 4.0.1. I reported this before, but I confirmed this bug by simpler
examples. Please try these examples on your machines and let me know
what happens. Program (1) does produce out of memory error. (2) does not
produce any error.
(1) Error stuff.
=====================cut here===============================================
// newtest.cc
#include <stream.h>
#include <math.h>
main()
{
float array[100];
float window[100];
float *res, *product(float*, float*);
int i;
for (i = 0; i < 100; i++)
{
array[i] = (float)i;
window[i] = cos(M_PI*(i-50)/100);
}
for (i = 0; i < 1000000; i++)
{
res = product(array, window);
delete[100] res;
}
exit(0);
}
float *product(float* array, float* window)
{
int i;
float* temp = new float[100];
for (i = 0; i < 100; i++)
temp[i] = array[i]*window[i];
return temp;
}
==============================================================================
(2) The following program which basically replaces new and delete to malloc
and free works fine without any error.
=====================cut here=================================================
// newtest2.cc
#include <stdio.h>
#include <math.h>
main()
{
float array[100];
float window[100];
float *res, *product(float*, float*);
int i;
for (i = 0; i < 100; i++)
{
array[i] = (float)i;
window[i] = cos(M_PI*(i-50)/100);
}
for (i = 0; i < 1000000; i++)
{
res = product(array, window);
free(res);
}
exit(0);
}
float *product(float* array, float* window)
{
float *temp;
int i;
temp = (float*) malloc(sizeof(float)*100);
for (i = 0; i < 100; i++)
temp[i] = array[i]*window[i];
return temp;
}
==============================================================================
Both of them were compiled with
$ g++ -g -O -m68881 -o newtest newtest.cc -lg++ -lm
style.
Does g++-1.35.* on Sun3 OS 4.0.1 produce the same bug?
Thank you very much,
Naoki Saito (saito@sdr.slb.com)
Schlumberger-Doll Research
Re: new and delete bug report 2
Author: Joseph E. Sacco
Date: Fri, 02 Jun 1989 20:17
Date: Fri, 02 Jun 1989 20:17
16 lines
1123 bytes
1123 bytes
I observed the same results on a SUN4 using g++-1.35.1-. The problem
seems to be with the statement "delete[100] res; " If this statement
is replaced by "delete res;" all is well under g++.
This example is quite like the one on page 92 of Bjarne's book. Since you
are not deleting a vector of class objects [see section 5.5.5] the book
suggests "... the vector size provided by the user is ignored ..."
This seems to be the case under Cfront1.2 where your program runs
with or without [100] appended to delete [albeit slower by a factor
of two ].
JOE
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads