C: using a lot of structures can make a program slow?

I encode a breakout clown. I had one version in which I had only one depth of structures. This version runs at 70 frames per second.

For clarity in the code, I decided that the code should have more abstractions and create more structures. In most cases, I have two two three levels of depth of structures. This version runs at 30 frames per second.

Since there are other differences besides structures, I ask you: can using a large number of C structures significantly slow down the code?

For example, in the second version, I use:

struct Breakout
{
   Ball ball;
   Paddle paddle;
   Level* levels;
}

struct Level
{
   Bricks* bricks;
}

So, I use breakout.levels [level_in_play] .bricks [i] .visible many times, for example. Will this be a possible cause?

Thank.

+5
4

. , :

  • , ,
  • , .

, , , . , malloc, , .

+11

-, , . - . , , , . .

, . malloc free, , , , . , , . / , , , , malloc .

, . , .

+4

( ) . , → , , , . , c->b->a , c , , b, , a, , . . c.b.a c, , . 2 5.

, , . , ( ), . .

, , , - . . , , ( ) , , .

+4

" " , - . " ", , . , . , .

, , , , , . ( , ), , .

If you have a profiling tool, profile the code to see where a performance failure occurs.

+1
source

All Articles