Advertisement

Why is one function faster than the other

Started by October 11, 2000 01:40 AM
14 comments, last by Nazrix 24 years, 3 months ago
        
inline void Plot_Pixel_Faster16(int x, int y, USHORT pixel,    
 USHORT *video_buffer, int lpitch16)
{
// this function plots a pixel in 16-bit color mode

// assuming that the caller already locked the surface

// and is sending a pointer and byte pitch to it


// write the data

video_buffer[x + y*lpitch16] = pixel;

} // end Plot_Pixel_Faster16




USHORT Get_Color(int x, int y,USHORT *video_buffer, int lpitch16)
{
	USHORT pixel;
	 pixel=video_buffer[x + y*lpitch16];
	return pixel;
}

        
Basically my problem is that I have 2 functions: Get_Color() gets the color value and then I do a calculation on the number then pass the color value to Plot_Pixel_Faster16() Plot_Pixel_Faster16() which plots a pixel with a certain color value in 16 bit color mode. Calling Get_Color() seems to be significantly slower than calling Plot_Pixel_Faster16(). I've tried them seperately and I can clearly tell that Get_Color() is slowing things down. I'm of course Locking the back surface before I do this stuff BTW. The 2 functions seem to be doing such similar things. Is writing to memory faster than reading it perhaps? """" "'Nazrix is cool' -- Nazrix" --Darkmage --Godfree"-Nazrix" -- runemaster --and now dwarfsoft" -- dwarfsoft --pouya" -- Nazrix ""You see... I'm not crazy... you see?!? Nazrix believes me!" --Wavinator Need help? Well, go FAQ yourself. Edited by - Nazrix on 10/11/00 1:41:46 AM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Reading video memory has always been significantly slower than writing to it. It''s just how video memory works.

------------------------------
#pragma twice


sharewaregames.20m.com

Advertisement
thanks for the quick reply...

hmmm....that sucks



"""" "'Nazrix is cool' -- Nazrix" --Darkmage --Godfree"-Nazrix" -- runemaster --and now dwarfsoft" -- dwarfsoft --pouya" -- Nazrix
""You see... I'm not crazy... you see?!? Nazrix believes me!" --Wavinator

Need help? Well, go FAQ yourself.



Edited by - Nazrix on October 11, 2000 9:22:31 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Also, the pixel plot is an inline function, which means you eliminate the overhead of calling the function, and passing all those parameters. That stuff (plus a return value) is all present in the GetPixel() function though, and it''s probably eating up more time than actually reading the memory. You might want to use a macro for GetPixel(), or just use the expression yourself in each instance of its use, rather than having a function call.

-Ironblayde
Aeon Software
"Your superior intellect is no match for our puny weapons!"
The getColor() fn also has to allocate stack space for it''s local variable, and also for a return value. But as stated above, making it inline will certainly speed it up.

Even better, if you can calculate the location in memory ONCE (x+y * lpitch16) and use it again later, that''ll save an add and a multiply, in addition to an array index.

VyvyanBasterd
Oh I see...thanks a lot


"""" "'Nazrix is cool' -- Nazrix" --Darkmage --Godfree"-Nazrix" -- runemaster --and now dwarfsoft" -- dwarfsoft --pouya" -- Nazrix
""You see... I'm not crazy... you see?!? Nazrix believes me!" --Wavinator

Need help? Well, go FAQ yourself.
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Advertisement
allocating space on the stack takes one reg inc, not much but i guess its there.

just add the word inline before the Get_Color function, that should speed it up quite a bit! right now you''re calling a funcion for each pixel you read!
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
yeah I am calling the function for every pixel...

Oh so inline makes it as if the function is in the main function...as if you''re not calling the function?


"""" "'Nazrix is cool' -- Nazrix" --Darkmage --Godfree"-Nazrix" -- runemaster --and now dwarfsoft" -- dwarfsoft --pouya" -- Nazrix
""You see... I'm not crazy... you see?!? Nazrix believes me!" --Wavinator

Need help? Well, go FAQ yourself.
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
You''re absolutely right Nazrix
ah ha!
It''s about time I''m right about something


"""" "'Nazrix is cool' -- Nazrix" --Darkmage --Godfree"-Nazrix" -- runemaster --and now dwarfsoft" -- dwarfsoft --pouya" -- Nazrix
""You see... I'm not crazy... you see?!? Nazrix believes me!" --Wavinator

Need help? Well, go FAQ yourself.
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi

This topic is closed to new replies.

Advertisement