PDA

View Full Version : reference table and Qt compilation



timmu
5th September 2012, 21:45
I have a program that needs to read in a reference table during runtime. The table is basically two 1-dimensional arrays of doubles (QList<double>). Currently I do it by referring to a function which is nothing more than the statements for arrays:



QList<double> array1, array2;
void readRef()
{
array1[0]=2.45; array2[0]=5.17;
array1[1]=3.78; array2[1]=3.12;
.....
array1[1700]=4.67; array2[1700]=0.12;
}


This method should work, but I run into weird problems. For example it compiles on 32 Debian to give a 1 MB executable which runs fine. When I compile the same program on 64 bit Scientific Linux (RedHat) it takes a long time to compile and the executable is 70 MB and it won't run (I get a weird message that an X-something is not found). I'm pretty sure that my functions that contain all the array definitions cause this because without this table the program runs fine on both systems. Does anyone know what is happening. Is there something Qt-specific about compiling programs that contain functions with only array statements?
Thank you!

timmu
6th September 2012, 11:57
I got the program to work. There was a problem with what i included (#INCLUDE). However the rest of the problem is still there. My reference table is only 50 kb of text. When I compile the program so that it becomes part of my program (see above) the size of my executable jumps from 1 mb to 70 mb! Why doesn't it go from 1 mb to 1.05 mb? What am I missing? Maybe I should use other options to compile. Right now I simply do:

qmake -project
qmake
make

Thanks!

d_stranz
6th September 2012, 17:14
Where do you set the sizes of the two QLists to 1700? I sure hope you do, because QList::operator[]() won't "grow" the list if the array index is out of bounds.

Possibly the size difference is partly due to the size of a double on the two systems. Have you added something like "qDebug() << sizeof( double );" to see what it actually is?

But I am guessing that the change in the size of the program has nothing to do with your data table, but more to do with the operating system and how it links the executable. On the 64-bit system, it may be statically linking to libraries that are dynamic on your Debian system, for example.

timmu
7th September 2012, 09:25
I set the size of the array like this.



QList<double> array1, array2;

for (i=0; i<1701; i++) {array1.append(0.0); array2.append(0.0);}

void readRef()
{
array1[0]=2.45; array2[0]=5.17;
array1[1]=3.78; array2[1]=3.12;
.....
array1[1700]=4.67; array2[1700]=0.12;
}


If the size of double differs between the two systems, then there is nothing I can do about that, right? Would you recommend using "const" with array definition somehow?

I think it makes sense that the two systems do the linking differently. But how would I change the way the linking is done?

wysota
8th September 2012, 07:47
When I compile the program so that it becomes part of my program (see above) the size of my executable jumps from 1 mb to 70 mb! Why doesn't it go from 1 mb to 1.05 mb?
Are you compiling in release or debug mode?

d_stranz
13th September 2012, 00:22
for (i=0; i<1701; i++) {array1.append(0.0); array2.append(0.0);}

Do this first for efficiency:



array1.reserve( 1701 );
array2.reserve( 1701 );

for (i=0; i<1701; i++) {array1.append(0.0); array2.append(0.0);}


Without it, your arrays will be repeatedly reallocated as you add more to them.

And as wysota asks, compiling in debug vs. release mode could cause the difference in program size.