Global Variable vs Struct Variable Question
From: Bryan Parkoff (spamtrap_at_crayne.org)
Date: 03/28/05
- Next message: Tim Roberts : "Re: Reading a sector"
- Previous message: David J. Craig: "Re: BIOS Assembly"
- Next in thread: Nathan Moore : "Re: Global Variable vs Struct Variable Question"
- Reply: Nathan Moore : "Re: Global Variable vs Struct Variable Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Mar 2005 07:39:08 +0000 (UTC)
I have read Pentium IV Optimization manual that it explains to avoid
global variable because it is slow. MOV instruction has to direct memory
address to retrieve global variable, but it does not have pointer. It makes
sense that global variable has its own memory address individually.
Individual memory address does not store in the cache.
Now, some local variables are stored in struct that struct always have
pointer. MOV instruction has to direct pointer once before it begins to
indirect memory address to retrieve local variable through pointer like
struct. Pointer does store in the cache because pointer is used again and
again.
My question is -- struct and class in C++ are useful for local
variables, but it is a very bad idea to bind member functions through
pointer. Member functions inside struct or class can slow and degrade the
performance on Pentium IV. It is preferable to use global functions outside
of struct or class while global functions can still access local variable
inside struct or class.
My test with timing stamp shows that member function inside struct and
class are slower than global functions. How can you please explain why it
happens? Why do programmers encourage to use member functions through
pointer because they claim that member functions can be stored in the cache
for better performance?
It is very important to me that I need to know.
Bryan Parkoff
- Next message: Tim Roberts : "Re: Reading a sector"
- Previous message: David J. Craig: "Re: BIOS Assembly"
- Next in thread: Nathan Moore : "Re: Global Variable vs Struct Variable Question"
- Reply: Nathan Moore : "Re: Global Variable vs Struct Variable Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|