[Wolves] ofstream hanging

Tom Edwards lists at t0m.me.uk
Wed Mar 3 09:40:23 GMT 2004


Hello All,
	Just a question mainly about g++ programming as I have a dooley of a bug and 
I have no idea why.

What I want to do is open a file, append the contents of a structure to it 
then flush the stream and close the file. 

So I do:

        std::cout << "Here 1" << endl;
	ofstream stream1("./file1.dat", ofstream::app | ofstream::binary);
	std::cout << "Here 2" << endl;
	stream1.write((char *)output, sizeof(struct statRecord));
	std::cout << "Here 3" << endl;
	stream1.flush();
	std::cout << "Here 4" << endl;
	stream1.close();
	std::cout << "Here 5" << endl;

however the output of the program is:

Here 1

and then it just hangs....

if i run it through gdb, i get
Program received signal SIGINT, Interrupt.
0x401843bc in mallopt () from /lib/i686/libc.so.6
(gdb) up
#1  0x40183f05 in mallopt () from /lib/i686/libc.so.6
(gdb) up
#2  0x40182cb8 in malloc () from /lib/i686/libc.so.6
(gdb) up
#3  0x400bc37e in operator new(unsigned) () from /usr/lib/libstdc++.so.5
(gdb) up
#4  0x400bc4ad in operator new[](unsigned) () from /usr/lib/libstdc++.so.5
(gdb) up
#5  0x4006b99d in std::basic_filebuf<char, std::char_traits<char> 
>::_M_allocate_internal_buffer() () from /usr/lib/libstdc++.so.5
(gdb) up
#6  0x4006b752 in std::basic_filebuf<char, std::char_traits<char> >::open(char 
const*, std::_Ios_Openmode) () from /usr/lib/libstdc++.so.5
(gdb) up
#7  0x0804d132 in simulationRun::startRun() (this=0x10) at ios_base.h:94
94        { return _Ios_Openmode(static_cast<int>(__a) | 
static_cast<int>(__b)); }
(gdb) up
#8  0x0804b765 in main (argc=134547832, argv=0xa) at spinSimulation.cpp:304
304         thisSimulationRun->startRun ();

So its stalling in the mallopt statement, and that is as far as I can go.

Does anyone know why this is happening?

Tom

PS.

If i do the same thing in C.

FILE *stream1 = fopen("file1.dat", "a");
fwrite(output, sizeof(struct statRecord), 1, stream1);
fflush(stream1);
/* It hangs here */
fclose(stream1);

PPS I know I should error check the return values of the streams but I was 
just doing a quick check on the code and didn't get round to it.




More information about the Wolves mailing list