Here's some code that creates a file of 500,000 lines, saves it to disk, loads it, then draws it. For some reason, it takes twice as long to draw then the LineTo Api method... go figure...




To use the code below you have to:
put the code in a module
set startup properties of the project to Sub Main
add a Form (Form1) to your project
Check 'DirectX 7 for Visual Basic Type Library' under References


VB Code:
  1. Option Explicit
  2. 'determines performance of execution for testing purposes only
  3. Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
  4.  
  5. Private Type mapLineType
  6.     XPosStart As Single
  7.     YPosStart As Single
  8.     XPosEnd As Single
  9.     YPosEnd As Single
  10.     Colour As Long
  11.     Thickness As Single
  12. End Type
  13. Private mapLine(500000) As mapLineType
  14. 'below type is needed for LineTo and MoveEx API functions
  15. Private Type POINTAPI
  16.         x As Long
  17.         y As Long
  18. End Type
  19.  
  20. Private DX7 As New DirectX7
  21. Private DD7 As DirectDraw7
  22. Private Primary As DirectDrawSurface7
  23. Private Back As DirectDrawSurface7
  24.  
  25. Public Display As Form1
  26.  
  27. Private Sub InitialiseDirectX()
  28. Dim ddsd As DDSURFACEDESC2, Size As RECT
  29. Dim Clip As DirectDrawClipper
  30.  
  31.     'Instantiate the main DX DirectDraw
  32.     Set DD7 = DX7.DirectDrawCreate("")
  33.    
  34.     'Negotiate a normal windowed display
  35.     DD7.SetCooperativeLevel Display.hWnd, DDSCL_NORMAL
  36.    
  37.     'Create the primary surface used to display completed images
  38.     ddsd.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
  39.     Set Primary = DD7.CreateSurface(ddsd)
  40.    
  41.     'Create and attach a Clipper to the Primary surface
  42.     Set Clip = DD7.CreateClipper(0)
  43.     Clip.SetHWnd Display.hWnd
  44.     Primary.SetClipper Clip
  45.    
  46.     'Create a back surface used to compose images before display
  47.     ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
  48.     ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
  49.     ddsd.lWidth = Display.ScaleWidth
  50.     ddsd.lHeight = Display.ScaleHeight
  51.     Set Back = DD7.CreateSurface(ddsd)
  52.    
  53. End Sub
  54. Public Sub cleanup()
  55.  'Reset the display back to the original windows
  56.     DD7.RestoreDisplayMode
  57.    
  58.     'Release objects
  59.     Set DX7 = Nothing
  60.     Set DD7 = Nothing
  61.     Set Back = Nothing
  62.     Set Primary = Nothing
  63.     Unload Form1
  64.     Set Form1 = Nothing
  65. End Sub
  66.  
  67.  
  68. Public Sub main()
  69. Dim mypointapi As POINTAPI
  70. Dim EmptyRect As RECT, DestRect As RECT
  71. Dim i As Long
  72. 'needed for conversion from twips to pixels with API functions
  73. Dim picture1width As Long
  74. Dim picture1height As Long
  75.  
  76. 'performance measuring variable
  77. Dim start As Long
  78. Set Display = New Form1
  79. Display.ScaleMode = vbPixels
  80.    
  81.     'Setup and initialise the DX environment and the Vectoid population
  82. InitialiseDirectX
  83. Form1.Show
  84. picture1width = (Form1.Width / Screen.TwipsPerPixelX)
  85. picture1height = (Form1.Height / Screen.TwipsPerPixelY)
  86. 'make some RANDOM DATA
  87. For i = 1 To 500000
  88. mapLine(i).XPosStart = Int(picture1width * Rnd)
  89. mapLine(i).YPosStart = Int(picture1height * Rnd)
  90. mapLine(i).XPosEnd = Int(picture1width * Rnd)
  91. mapLine(i).YPosEnd = Int(picture1height * Rnd)
  92. mapLine(i).Colour = Int(10000 * Rnd + 1)
  93. mapLine(i).Thickness = Int(1 * Rnd + 1)
  94. Next
  95. Open ("C:\testfile.tst") For Binary As #1
  96. Put #1, 1, mapLine
  97. Close #1
  98.  
  99. 'Begin load and draw
  100. start = GetTickCount
  101. Open ("C:\testfile.tst") For Binary As #1
  102. Get #1, 1, mapLine
  103. Close #1
  104. Debug.Print "loaded in : " & (GetTickCount - start) / 1000 & " seconds"
  105.  
  106. start = GetTickCount
  107.     'clear the back surface
  108.     Back.BltColorFill EmptyRect, vbBlack
  109.    
  110.     'draw the lines to the back surface
  111.     For i = 1 To 500000
  112.         Back.SetForeColor mapLine(i).Colour
  113.         Back.DrawLine mapLine(i).XPosStart, mapLine(i).YPosStart, mapLine(i).XPosEnd, mapLine(i).YPosEnd
  114.     Next
  115.      
  116.     'Get the latest size and position of destination window
  117.     DX7.GetWindowRect Display.hWnd, DestRect
  118.    
  119.    'Blt the back surface to the primary surface
  120.    Primary.Blt DestRect, Back, EmptyRect, DDBLT_WAIT
  121.    
  122.  
  123. Debug.Print "Drawn in :" & (GetTickCount - start) / 1000 & " seconds"
  124. End Sub