Draw a complete frame to a memory or system bitmap.
Optionally wait for retrace (vsync()).
Blit the memory bitmap to screen.
Allocate 2 pages of vram (2 video bitmaps).
Select one page to display, one for drawing.
Draw a complete frame to the drawing page.
Flip the pages so that the drawing page becomes the visible page and vv. Unfortunately, flipping always waits for a retrace, so you probably lose valuable cpu time here.
Works the same as page flipping, but you allocate 3 pages, not 1. You have now one visible page, one queued page and one drawing page. Each time you finish drawing a frame, you flip queued and drawing page, thereby queueing the drawing page. Allegro (or the graphics driver or that tiny little dwarf inside your computer case) flips queued and visible frame on each retrace, except when no page has been queued.
Now, each method has its advantages.
Double buffering is very easy to implement, and it can live with minimum vram requirements (1 page). On modern machines, the memory transfer through the bus is not very expensive, so it can run at high frame rates. All video cards and platforms support this. It does, however, produce the "tearing" issue.
Page flipping is "cleaner", and, on some machines and depending on what you are doing, can be faster than double buffer. But: Not all video cards / platforms support page flipping, and you need enough vram to hold 2 pages. A big disadvantage is that flipping can only happen while retracing, so you lose time here.
Triple buffering is usually the fastest and smoothest solution, but it requires 3 pages of vram, and, of course, video card and platform must support it.
If i calculate exactly when the frame is drawn i blit to screen at that moment,will that problem dissapear?
This is exactly what vsync() tries to do, so I'm afraid this will not solve your problem.