[Gc] Crash on startup when using delete on Win32

Jiawen Chen jiawen at MIT.EDU
Mon Aug 28 17:14:06 PDT 2006


Hello,

	I recently compiled gc 6.8 on Windows, 32-bit, using Visual Studio 2005 
and the Intel C++ Compiler, version 9.1.022.  I used the following -D flags:

_DEBUG
SILENT
GC_BUILD
WIN32
_WINDOWS
ALL_INTERIOR_POINTERS
__STDC__
GC_WIN32_THREADS
GC_OPERATOR_NEW_ARRAY

	The gc works marvelously in pure C.  However I would like to use it 
with C++.  It crashes horribly when I have delete[] anywhere in the 
code.  I used the following (I was benchmarking collected vs uncollected):

#include <cstdio>
#include <ctime>
#include "gc/gc_cpp.h"

void uncollected()
{
	int nIters = 100000;

	for( int i = 0; i < nIters; ++i )
	{
		printf( "i = %d\n", i );
		int* arr = new ( NoGC ) int[ 100 ]; // I also tried ::new
		printf( "i = %d, after new\n", i );
		delete[] arr; // I also tried delete without the []
	}
}

int main()
{
	GC_INIT();
	printf( "Hello world!\n" );
	uncollected();
}

It prints "i = 0", then "i = 0, after new" and then dies.  This happens 
with or without GC_INIT().  It doesn't crash if I remove the delete[]. 
It also worked fine when I used new ( UseGC ) without delete[]s.

It seem to die in obj_map.c, according to the debugger:

/* Add a heap block map for objects of size sz to obj_map.	*/
/* Return FALSE on failure.					*/
GC_bool GC_add_map_entry(sz)
word sz;
{
     register unsigned obj_start;
     register unsigned displ;
     register map_entry_type * new_map;
     word map_entry;

     if (sz > MAXOBJSZ) sz = 0;
     if (GC_obj_map[sz] != 0) {
         return(TRUE);
     }

////////////////////////////////////////////////////
// the arrow of the debugger points at the next line
////////////////////////////////////////////////////

     new_map = (map_entry_type *)GC_scratch_alloc(MAP_SIZE);



////////////////////////////////////////////////////

Any ideas?

Many thanks,

Jiawen Chen


More information about the Gc mailing list