Sign in to follow this  

Too much global data defined in a file,what can I do?

This topic is 3460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to build a game,I am using Borland 3.1.. My friend build for me two models,a car and a race track,and gave me them in form of array,like this one(the race track): float theRaceTrack[314][3][4]= {{{17.642202,9.860716,0.500000,1},{18.620651,9.860716,0.500000,1},{17.642202,14.083413,0.500000,1}}, {{17.642202,14.083412,0.500000,1},{18.620651,9.860715,0.500000,1},{18.620651,14.083412,0.500000,1}}, {{18.620649,9.860715,0.500000,1},{34.275837,9.860715,0.500000,1},{18.620649,14.083412,0.500000,1}}, {{18.620653,14.083412,0.500000,1},{34.275837,9.860715,0.500000,1},{34.275837,14.083412,0.500000,1}}, {{34.275837,9.860715,0.500000,1},{35.254284,9.860715,0.500000,1},{34.275837,14.083412,0.500000,1}}, {{34.275837,14.083412,0.500000,1},{35.254284,9.860715,0.500000,1},{35.254284,14.083412,0.500000,1}}, {{17.642202,14.083412,0.500000,1},{18.620651,14.083412,0.500000,1},{17.642202,14.083412,-0.500000,1}}, {{17.642202,14.083413,-0.500000,1},{18.620651,14.083413,0.500000,1},{18.620651,14.083413,-0.500000,1}}, {{18.620651,14.083412,0.500000,1},{34.275837,14.083412,0.500000,1},{18.620651,14.083412,-0.500000,1}}, {{18.620653,14.083412,-0.500000,1},{34.275841,14.083412,0.500000,1},{34.275841,14.083412,-0.500000,1}}, {{34.275837,14.083413,0.500000,1},{35.254284,14.083413,0.500000,1},{34.275837,14.083413,-0.500000,1}}, {{34.275837,14.083413,-0.500000,1},{35.254284,14.083413,0.500000,1},{35.254284,14.083413,-0.500000,1}}, {{17.642202,14.083412,-0.500000,1},{18.620651,14.083412,-0.500000,1},{17.642202,9.860715,-0.500000,1}}, {{17.642202,9.860715,-0.500000,1},{18.620651,14.083412,-0.500000,1},{18.620651,9.860715,-0.500000,1}}, {{18.620651,14.083412,-0.500000,1},{34.275837,14.083412,-0.500000,1},{18.620651,9.860715,-0.500000,1}}, {{18.620651,9.860715,-0.500000,1},{34.275837,14.083412,-0.500000,1},{34.275837,9.860715,-0.500000,1}}, {{34.275837,14.083412,-0.500000,1},{35.254284,14.083412,-0.500000,1},{34.275837,9.860715,-0.500000,1}}, {{34.275837,9.860715,-0.500000,1},{35.254284,14.083412,-0.500000,1},{35.254284,9.860715,-0.500000,1}}, {{18.620651,9.860715,-0.500000,1},{34.275837,9.860715,-0.500000,1},{18.620651,9.860715,0.500000,1}}, .. .. now,with the car and the race track I have about 530 cells..and when i try to run the program this is the error I get "Too much global data defined in a file" how can I fix it,without delet any of the array(or make them smaller..) anyway?? or any ideal how can load this models into my project..? so they would work..

Share this post


Link to post
Share on other sites
Ouch. You might be able to try a different compiler. I know Microsoft's compiler doesn't allow as much local, stack-allocated data as gcc allows. I don't know about static data, but it might be worth a shot.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalisto
static data? what you mean?


Global data like your array is put into the executable in a so-called static data segment. It's called static because it always exists in your program.

Data that is local to a function is called "stack dynamic" or automatic. This data is allocated for a function on the stack when the function is called (the compiler does this for you).

Data that is allocated with new or malloc is called "heap dynamic". It is allocated when the call to new or malloc is made.

Back to the point though. Did your friend use a modeling program to come up with all of that data? If so, maybe you could get him to export to another format that can be read in from a file. Worst comes to worst, you can copy the array to a text file directly and write code to read it in at run-time.

Doing this would move the allocation from static to heap-dynamic and get rid of that error.

Share this post


Link to post
Share on other sites
Ehm, have you thought of loading the data from file into memory instead of exchanging the meshes (or whatever else) through C++ code ?

Writing your own parser for a text file shouldn`t really take you more than few hrs anyway. After all, it`s just float values.

It could look like this:

class CVertex
{
D3DXVECTOR4 Pos;
};

class CFace
{
CVertex P1,P2,P3;
};

class CMesh
{
CFace * Faces;
CMesh () : Faces(NULL);
~CMesh () { if (Faces != NULL) delete [] Faces; }
void LoadMesh (char * strPath, int FacesCount)
{
Faces = new CFace [FacesCount];
// Load the data from file
...
}
}

Share this post


Link to post
Share on other sites
ok its sound not so difficult...
its what I thought about:

int allocated;//If 1 then a shape is already exists
int vcount;//Vertexes counter

void Allocate()//Allocates memory for the loaded shape
{
float array[vcount][3][4];
allocated=1;

}

void Deallocate()//Deallocates the memory
{
delete []array;
allocated=0;
vcount=0;


}

void LoadFile(const char *filename) Loads a shape from an .txt file
{

if(vcount!=0)
Deallocate();

*Get vertices count from file...(vcout=...)

if(vcout!=0)
Allocate();

//for each vertex ,get (x,y,z)

for(i=0;i<vcount;i++)
{
x=...//get 'x' value from file
y=...//get 'y' value from file
z=...//get 'z' value from file
for(j=0;i<3;i++)
{
array[i][j][0]=x;
array[i][j][1]=y;
array[i][j][2]=z;
array[i][j][3]=1;
}

}

should it work? and the problem is that I don't know how to get the info from the file(how to load it)..what function to use? how do i get it?

Share this post


Link to post
Share on other sites
You won`t be able to allocate the memory your way. If you really want to use 3 indices [][][], you`d have to go for dynamic multidimensional arrays which would be an unnecessary overkill for you. It will be much easier for you (to debug and play with it) if you create the classes that I proposed. That way you`ll always know 100% if you`re dealing with a vertex or a face or a mesh array.

As for file access, try googling some file access tutorials. Try using fstream for example. See http://www.cplusplus.com/reference/iostream/fstream/

Although it might seem an overkill, you`ll need only to open the file, read the data and close it. So, you`ll most likel use just open (), close () and read () / getline ()

Share this post


Link to post
Share on other sites
Well, yes, you should learn to load data from files, makes your live much easier (and your compiling-time shorter :)).

Furthermore I don't know where you're going with this project? Are you making a game? It seems you don't know the basics enough to start on such a thing, correct me if I'm wrong ofcourse :) ... For example: do you know how to do object oriented programming? (like VladR's example code)

Maybe you should first do some smaller side-projects:
a. Loading a file, reading it's data, closing it, releasing memory.
b. Set up a structure to store all the loaded data, different classes, etc.
c. Try to display a 3D-model on your screen (reading tutorials)

d. Once you've tried these three things seperately and successful (thus also cleaning up when your application is finished), I'd suggest combining it into an application with which you can display a single 3D-model loaded in from a file.

e. After that I'd expand the application so you could display multiple 3D-models on the same time and rotate/translate them according to some user input.


You could also try and learn on the run, but I think you'll get disappointed/confused of your own code by the time you reach point d. or e. Because by then your project is filled with work-arounds and dirty solutions.


PS: that std::fstream suggestion of VladR is also a good one, because then you don't get the trouble of manually parsing out the floats out of a array of characters including spaces, semicolons, brackets, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalisto
I am trying to build a game,I am using Borland 3.1..


You might be hitting the 64k boundary. To be honest, I've forgotten the details, but I know that back in the day it was a problem and one had to jump through many hoops and loops to get larger data sets simply due to the way memory worked.

Why are you using a 16 years old compiler anyway?

Share this post


Link to post
Share on other sites

This topic is 3460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this