🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #102

__builtin_new & __builtin_delete (fwd)

#102
From: John Edstrom
Date: Tue, 21 Jul 1992 12:56
87 lines
2933 bytes
I think I've narrowed the problem in __builtin_delete down to a
problem with __builtin_new.  Here is the simplest program I could
imagine to test their performance:

I'm using gcc 2.2.2 on Sun SPARK, built with: "configure sun4"

------------------------
#include <fstream.h>

#define INC  100
#define TYPE int

main()
{
  int  i;
  TYPE *p1, *p2 = NULL;

  for (i = 0; i < 5; i++) {
    p1 = new TYPE[INC];
    cout.form("%3d %u %u\t", i, (int)p1, (int)p1+(sizeof(TYPE)*INC));
    if (p2 != NULL)
      cout.form("%5d", (p1-p2)/sizeof(TYPE));
    p2 = p1;
    cout << "\n";
  }
}
-----------------------------------------

here is the output of the debugger, notice that the calls to
__builtin_new request the proper number of bytes but subsequent
invocations of new get pointers located 1/4 the proper distance from
the start of the previouw block.  It seems that __builtin_new is doing
something wrong with scaling for the size of the data type when it
tracks memory usage although it does request the right amount of
memory. Any attempt to write to one array will write over newer
arrays.  God knows what happens when I delete them.

 If I use type double instead of int then the distance allocated
blocks is only sufficient for 12 doubles, not the requested 100.

This is too fundamental a problem to have been relased without
somebody having noticed so I presume I'm doing something wrong.  Does
anybody know what it is?

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

GDB 4.6, Copyright 1992 Free Software Foundation, Inc... 
(gdb) break __builtin_new
Breakpoint 1 at 0xa9b4
(gdb) run
Starting program: /files/home/Lukowiak/edstrom/ftp/meshcach/src/tmp 

Breakpoint 1, 0xa9b4 in __builtin_new (sz=400)
Current Language:  auto; currently c
Type checking:     auto; currently off
Range checking:    auto; currently off
(gdb) cont
Continuing.
 
Breakpoint 1, 0xa9b4 in __builtin_new (sz=8192)
(gdb) 
Continuing.
  0 76256 76656  

Breakpoint 1, 0xa9b4 in __builtin_new (sz=400)
(gdb) 
Continuing.
  1 84864 85264   538

Breakpoint 1, 0xa9b4 in __builtin_new (sz=400)
(gdb) 
Continuing.
  2 85272 85672    25

Breakpoint 1, 0xa9b4 in __builtin_new (sz=400)
(gdb) 
Continuing.
  3 85680 86080    25

Breakpoint 1, 0xa9b4 in __builtin_new (sz=400)
(gdb) 

--
 RM 2104, HSc Building,  Div. Neuroscience
 U. Calgary School of Medicine,  3330 Hospital Drive NW
 Calgary, Alberta       T2N 3Y4
 (403) 220 4493  (wk)
Technical Details
Message-ID: <9207211256.AA05302@Elmer.hsc.ucalgary.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!elmer.hsc.ucalgary.ca!edstrom

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!elmer.hsc.ucalgary.ca!edstrom
From: edstrom@elmer.hsc.ucalgary.ca (John Edstrom)
Subject: __builtin_new & __builtin_delete (fwd)
Message-ID: <9207211256.AA05302@Elmer.hsc.ucalgary.ca>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 21 Jul 1992 12:56:21 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 88