Advertisement

local variable == SLOW?

Started by October 17, 2000 05:41 PM
33 comments, last by jho 24 years, 2 months ago
quote:
Then the memory allocation is exactly the same for both versions, however, the first code will take performance hit for the construction multiple times, am I right?

Yes.
quote:
Build in type has no construction costs? if I have a blank constructor for my class is it considered to have no construction costs?

Yes, but I believe it has to be inlined. Might depend on the compiler. If your constructor is defined like this in the header:
myClass::myClass () { }
..then I believe there is no construction costs. Something you should check the assembly listing for, though.

Note to AP: You''re correct. I wanted an unoptimized compile so you could see what was happening line-for-line. Also, I wanted to show that this is not an optimization feature, but a language feature.

Note to Gladiator: Other reasons your argument doesn''t work:
- there''s no way to differentiate between each of the new ''s'' arrays each time in the loop. If the first s is at BP-0, where''s the next one? And the next? How are they described as different symbols at compile-time?
- moving the stack pointer after you''ve updated the base pointer will mean you loose everything you''ve pushed. When you pop, you''re popping from a different stack location.
Stoffel, I never said anything about the C code being compiled to the ASM code I gave!!! What I said was, that''s what you SHOULD get without any optimization, and following the logic of the code.

Once you optimize the code, you get what YOU were suggesting, which certainly is better, and hence the compilers optimize that. Also, what I said at the end was that if YOU were to write YOUR OWN ASM CODE the latter way, then it would take a performance hit. That''s all I ever said. So, once again, you were 50% correct.

When discussing such a topic you should take into consideration what the compiler optimizes and what it doesn''t. If you use optimization, you''re 100% correct, if you write your own ASM code the way I wrote it, and test both code listings, then your investigation is wrong and you''re 0% correct. Get my point and what I''m trying to say here?

-------------------------------
I'll screw up whoever screws around with the gamedev forum!

..-=gLaDiAtOr=-..
Advertisement
quote:
Note to Gladiator: Other reasons your argument doesn''t work:
- there''s no way to differentiate between each of the new ''s'' arrays each time in the loop. If the first s is at BP-0, where''s the next one? And the next? How are they described as different symbols at compile-time?
- moving the stack pointer after you''ve updated the base pointer will mean you loose everything you''ve pushed. When you pop, you''re popping from a different stack location.


Once again, we''re not talking about how practical that code is. What we''re talking about here is efficiency in terms of speed.

-------------------------------
I'll screw up whoever screws around with the gamedev forum!

..-=gLaDiAtOr=-..
Gladiator:
This is my last post on the topic.
This is not an optimization, it''s a language feature.
Upon deeper consideration, I would venture to say that it''s true for ANY LANGUAGE that stack variables must be allocated between the call to the function and beginning of function execution. Otherwise, the stack would be rendered useless during the duration of any function, and there would be no way to access those variables because any loop would need an infinite variable declaration segment.

Let me repeat:
Any language that allocates stack variables can only do so one time, prior to executing the function.

Optimization has nothing to do with it. You do not know what you''re talking about. I''m glad others have learned from this discussion. I pity you that you don''t understand the fundamentals of computers, and hope you''re able to find some instruction in the future.
Stoffel, shut up... i don''t know how to explain this in English well, but I do know what I''m talking about and I understand the fundamentals of a computer. I''m not sure if what I''ve written sounds like what I wanted to say. Even when I read it myself, it doesn''t exactly explain what I mean, but that''s the best I can do with my limited vocabulary in the English language. Sorry man. Next time I''ll just not mention a word because of stupid English. Are you happy now? Aight... I''ll be back on this topic once I learn English well enough.. you''ll be sorry then you ever started the discussion....

quote:
I pity you that you don''t understand the fundamentals of computers.

Good use of the English language, but does not tell the truth about what I know and what I don''t. I''m sure I know better than you the fundamentals of computers. I can''t explain it well in English because of my limited vocabulary. Anyways, I think you''re 2 steps ahead of your feet.

I wish I had better English skills to prove your wrong, but for now you can believe you know better than me... since I can''t prove my worth''s to you.

Thanks for your time.

-------------------------------
I'll screw up whoever screws around with the gamedev forum!

..-=gLaDiAtOr=-..

This topic is closed to new replies.

Advertisement