Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!dino!uxc.cso.uiuc.edu!uxc.cso.uiuc.edu!ux1.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.sys.ibm.pc Subject: Re: Why are bitmap save/restores so slo Message-ID: <110200003@uxe.cso.uiuc.edu> Date: 14 Sep 89 23:05:11 GMT References: <3776@titan.camcon.co.uk> Lines: 39 Nf-ID: #R:titan.camcon.co.uk:3776:uxe.cso.uiuc.edu:110200003:000:1812 Nf-From: uxe.cso.uiuc.edu!mcdonald Sep 14 09:32:00 1989 >I am fiddling around with graphic objects in C++ on a PC (EGA mode) >and am frustrated by the time taken to save/restore areas of the >screen bit-map. >I have had a peek at the assembly code doing the pixel copying and it >seems to take around ten instructions per pixel. It is because of poor programming. The EGA has a bizarre but efficient architecture. The ega has a 350x640 pixels by 4 bits mode. That is 112 kbyte of data. So it won't fit, in the obvious way, two pixels to a byte, in one segment. They could have used two segments (a000:0000 to roughly b000:d000) or could have switched portions of map into one segment with an io register bit. But no, they went to separate bitplanes for the four bits, all in one segment. That way they get two whole screens in one segment. Or one 600x800 screen in a segment (on other vendors extended VGA cards). There are extremely efficient ways of copying areas from region to another of video memory. And, to copy to or from ordinary memory, retaining the planar maps, is very fast indeed. So is drawing lines or circles or text in a fixed color. The programmer just has to understand how it works and choose an efficient way to do it. Problem is, and this is evident most clearly in comp.lang.c, is that a lot of programmers learned to program by taking classes in a University somewhere, where they didn't stress enough (at all) the importance of efficiency. And, the graphics textbooks I see all seem to take some abstract model of a graphics device, rather than a real, albeit odd or grubby, one. So people write silly, slow code, not thinking hard enough how to do it fast. IF a programmer understands how the EGA works, it can go blazingly fast. Don't write "modular" or "structured" code: write FAST code, and it will go fast. Doug MCDonald