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

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

## 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 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 on other sites
static data? what you mean?

##### Share on other sites
Quote:
 Original post by Kalistostatic 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 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 shouldnt really take you more than few hrs anyway. After all, its 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 on other sites
ok its sound not so difficult...

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;

}

{

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[j][0]=x;
array[j][1]=y;
array[j][2]=z;
array[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 on other sites
You wont be able to allocate the memory your way. If you really want to use 3 indices [][][], youd 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 youll always know 100% if youre 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, youll need only to open the file, read the data and close it. So, youll most likel use just open (), close () and read () / getline ()

##### 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:
b. Set up a structure to store all the loaded data, different classes, etc.

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 on other sites
Quote:
 Original post by KalistoI 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 on other sites
Quote:
 Original post by KalistoI am using Borland 3.1.

Are you posting from a 486?

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• ### Who's Online (See full list)

There are no registered users currently online

×