'=========================================================================== ' Subject: WHY DOUBLE BUFFER? Date: 08-14-98 (18:00) ' Author: Sten Daniel Soersdal Code: Text ' Origin: prinz@mailexcite.com Packet: FAQS.ABC '=========================================================================== Why Double buffer ? -======================- Copyright Sten Daniel S›rsdal, 1998 Some programmers out there have asked me the question 'Why double buffer?' And the answer is quite simple. Of course there are alot of advantages with double buffering techniques versus non-double buffering. Alot of people tend to think that writing to the screen directly is faster, because they dont have to copy the buffer to the screen afterwards. This is somewhat true, but it has some major disadvantages; 1. Speed, its slower to manipulate the screen directly, the DRAM refresh takes alot of time. This means the onboard screen DRAM has to refresh very often. And the DRAM is 9 out of 10 times ALOT slower than the RAM you have in your computer. On my own computer my DRAM has an access time (yours will vary) of about 3.500 kb/second. And my RAM has about 65.000 kb/second access time. (Dell 486dx66.) This makes every graphics operation alot slower, for example when i smooth the screen or do alot of sprite operations. Even just drawing directly is slower, because during write/read the graphics card has to refresh, and the operation stalls. And in an average game or graphics application you do alot of reading and writing (mostly writing) to the screen memory. So unless you do less than pasting one single sprite to the screen, it _will_ be much more efficient to draw these in a virtual screen instead. 2. Flicker, because your hardware has to refresh its memory banks the user will often see the screen being redrawn. And of course the refresh of your monitor, makes slow operations look like they where done halfway before they are refresh yet again. On a really fast computer this will still be a problem, the time wasted isnt your CPU doing slow calculations, its the CPU time wasted while accessing screen memory. 3. Annoying, its much more calming to see a finished result planted on your screen instead of seeing it be done. I get all nerves when i see a game/routine that i can see updates the screen. Its much more calming to the general user to see the results instead of the process, this is in the back of your mind. Disadvantages, it take abit more memory to implement double buffering. For instance the memory it requires to have an equally large virtual screen memory bank. Thats about the only drawback. So a little summing up here. Create_a_virtual_screen Enter_correct_screen_mode DO Do_your_calculations Draw_your_calculations Wait_for_vertical_blank Copy_virtual_screen_to_real_screen Erase_virtual_screen ; Not always nessessary OD This pseudo code example will guarantee flickerless results, and a speed increase. Though most the of the gained speed from drawing to a virtual screen will be used to copy the virtual screen to the real screen, it _will_ give you a speed increase (unless your copy routine sucks) Regards Sten Daniel S›rsdal prinz@mailexcite.com Check out my PB13h library, it has _ultra_ fast mode 13h routines based around double-buffering (though not nessessary). The assembly code has been optimized to the fullest, cutting alot of corners, yet retaining full userfriendlyness. (PB3.2+) ---------------8<----[ TIMINGS.LST ]---->8------------------ Sten Daniel S›rsdal pRiNz software xxx-xxx-xxxxxx-xxxx * edited * First Meg / Timings First Meg Speed PC/XT Memory Area K/Sec Index Memory Cache 32248 62.3 0000 - 1CFF 18910 36.5 1D00 - 1DFF 29829 57.6 1E00 - 9EFF 18881 36.4 9F00 - 9FFF 23627 45.6 A000 - AFFF 3442 6.6 B000 - B7FF 18864 36.4 B800 - BAFF 2903 5.6 BB00 - BBFF 3375 6.5 BC00 - BFFF 2907 5.6 C000 - C7FF 18808 36.3 C800 - CFFF 1147 2.2 D000 - FFFF 18877 36.4 HMA 23863 46.1