fstream.read is acting funny (bad_alloc)

I had some strange issues with my code and it turned out to be that I raad a struct wrongly and thus all following structs would not give me the proper value.

The unexplicable and utterly strange problem arose when I tried to fix it and set it to read 12 bytes. Look at the snipped below. the size of the strcture (given by sizeof()) was 12. When reading it with 8, 9, 10, or 11 in size, it wouldn't even be visible in the task manager's memory monitor, but once I set it to 12 -- 2GB is allocated out of the blue and bad_alloc is thrown.

1
2
3
4
stream.seekg(header->dataOffset);
gtop = new gff::GtopData();
stream.read((char*)gtop, 12);
cout << sizeof(gff::GtopData) << endl;

stream is the fstream object I use.

I have no clue. The structure is merely 3 unsigned ints. Anyone who have any idea as for what happened?

EDIT: The problem happened to be somewhere else, but seemingly triggered by this.
Last edited on
You might start out by checking your return codes (if you aren't - your post doesn't show it!)
Topic archived. No new replies allowed.