problem while using vector.push_back [FIXED]

Started by
13 comments, last by Fruny 19 years, 1 month ago
well i have made a class for heightmaps which i will use for terrain. I have all of different heightmap files in a vector. heres my struct

struct TERRAIN
{
	BYTE HeightMap[1024*1024];
	int MAP_SIZE;
	int ID;
};


the thing is, when i push a vector with the hieghtmap data, the array is way to big for the vector (i think), so it causes an error. If i reduce the size of the byte array then it will work properly. Is there a way to fix this? thx jake [Edited by - jake_Ghost on March 28, 2005 6:36:43 PM]
Advertisement
What happens when you try to push that structure? Do you get an error message or something?
You could replace the BYTE array itself with a vector<BYTE>. A 1M struct is huge; it won't fit on the stack.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
You realize that structure is over 1MB big? Hopefully you don't want to push to many of them.

Anyway, it helps to mention what the error is when you say you get an error.
-Mike
its one of those window errors that says send error report or dont send. i am using the code from gametutorials.com for raw loading.
i just tried using vector<BYTE>. Had no effect. still got same error
I think the problem is probably that, even though vector uses the heap, when you do push_back you pass it a TERRAIN object that was created on the stack. And like Fruny said, that structure won't fit on the stack.
Quote:Original post by jake_Ghost
its one of those window errors that says send error report or dont send. i am using the code from gametutorials.com for raw loading.


It's a stack overflow. The default stack size is generally only 1MB. A single variable of that type is already bigger than that. Use dynamic allocation (e.g. a vector<BYTE>) instead of an array.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
ok well i cant use vector unfortunatly cause it screws up some other code i have so how do i do it normally using pointers and new statment.

can i do it like this??
BYTE *HeightMap;//and when i push the vector resize the heightmap arrayHeightMap = new BYTE[1024*1024];


ok thx guys i got it working now.

This topic is closed to new replies.

Advertisement