Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: frea on February 26, 2008
-
Hi!
I can't understand one thing. I've been writing a small program, and at one point i needed to use a struct more. Merely by adding it, and doing a single instruction using it the size jumped by 1.5kb uncompressed. I disassembled 2 versions, one with this single instruction one without. the asm code differed very slightly. ( ~12 lines in ~2k lines were different )
So, if the code doesn't differ, why am i getting such a huge change?
typedef struct Primitive_
{
unsigned int type;
float pos[ 3 ], col[ 3 ];
float rotx, roty;
union
{
float sphere;
float cube[ 3 ];
};
} Primitive;
Primitive prim[ PRIMITIVENUM ];
(...)
sub( vector1, prim[ id ].pos, vector2 ); //this line adds 1.5kb, sub is also called previously on different vectors
Stripping the contents of Primitive doesn't reduce size.
-
How big is PRIMITIVENUM?
Say around 50?
Thats your 1.5k there.
--
DBF debugging service.
-
#define PRIMITIVENUM 2
:)
changing to 10000 makes no size difference. ( all arrays are in .bss section )
edit: mistake, it causes diffrence.
But that what is surpricing that the difference is between PRIMITIVEMNUM beeing 2 and 3. What the hell? ( even if no code uses the array! )
edit2: it is even more werid. For purpouses of finding why i have such problem i have commented out the rest of the function. I tried compiling with -Os, and the size dropped greatly, now there is no jump on primnum 2 to 3. That what is interesting that by uncommenting the rest of function i get ~1.5kb again but, with -O2 i don't get 2x 1.5 kb but only 1x1.5kb. The uncommented part gives sixty-something byte diffrence in file size if used with -O2.
So the file size doesn't differ to much with -O2/-Os, but it has a werid growth when (un)commenting :).
edit3: don't ask me :). I've switched computers and now no werid behaviour. At home everything's ok :).
-
Maybe depending on size the compiler is bringing in a library routine like memcpy or mul to do some internal sums instead of doing them inline? But it sounds like your problem has gone away for now :)
Jim
-
It seems that the compiler at labs is somewhat broken :p. I comment ~30 function calls and get 20bytes less uncompressed, although it ereases ~100 lines of asm.