Re: virtual functions vs speed

From: JKop (NULL_at_NULL.NULL)
Date: 09/17/04


Date: Fri, 17 Sep 2004 08:17:12 GMT


> I have been thinking about using function pointers but that seems as
> nasty trick which will only create a lot development problems later on.

For the love of God that's exactly how virtual functions work!

Why do you think that you can access memory any faster than the compiler
can?! Running shoes?

Virtual functions work via pointers (just to cover my bases here: No, it
doesn't say this in the Standard ), as such, they'll be exactly the same
speed as if you used function pointers *yourself*, plus they're more
convenient.

On last thing:

If you're running Windows, have a look for "ramdrive.sys" on your machine.
It's been around since about DOS 6 I think. Anyway, let's say you have 128MB
of RAM, set up a 50MB Ramdisk. Copy 50MB from your harddisk to this ramdisk.
Play around with the data on the ramdisk; moving, copying, renaming. Note
how quick it is, and note that that's 50MB you're dealing with. On Windows,
a pointer is 32-Bit, which on Windows equals to 4 bytes.

50MB = 51,200 KB = 52,428,800 bytes

which is the equivalent of 13,107,200 pointers.

Now, how many pointers are *you* dealing with? 2? You have exactly *no*
worries.

Just a little side note here... ever played the game Mortal Kombat? Well
there's a character in it called Shang Tsung who can morph into every other
character in the game. So you hit a certain button sequence (forward forward
x) and he morphs. This was grand on the Super Nintendo, the new character
was loaded instantly from the game cartidge (in fact, it wasn't loaded at
all, the cartridge was accessed directly from the cartridge as if it *was*
memory). But then you had the Playstation, which used CD's. CD's aren't
nearly as fast as RAM nor cartridge; as such, the new character had to be
loaded. So you'd hit forward forward x and the game would stall for about 10
seconds, then you'd be able to play again. There was the same problem on the
PC, loading the character from a hardisk. *My remedy*? Copy the game to a
ramdisk and run it. Forward forward x and voila, instant morph!

Again, just to stress it, RAM is fast! And by fast I mean *FAST*. So don't
be worrying about 2 miserable little pointers!

-JKop