CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2012
    Posts
    7

    bmp file reading faster after first time ?

    hey guys, im making a program to "test darwinism" in C++ and im showing the results in a VB 2010 express app, the results consist of .800x800 bmp files displaying creatures eating , reproducing and evolving. the VB app only has a picture box and it changes the .image param in a timer so that it looks like a video : for example it reads : frame0.bmp then frame1.bmp etc. I get about 30frames seconds with this method (and alot of GB of .bmp files..)

    I've got a problem tho.. the .bmp files are read slower if they never have been read.. for example I get about 5frames/sec when im using new .bmp files while I get 30fps if the files have been read once.. only opening and closing the files doesnt make them load faster, I have to load the bitmap image. I noticed that opening the directory where the .bmp files are and letting windows make preview icons make them load faster too.. that looks weird to me.. something with indexing ?

    also , my c++ program which creates the .bmp files goes really fast for the 500first but then it becomes slower (even if It just writes black .bmp files in a closed loop). could it be that the hard disc gets overwhelmed by all the writing ?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: bmp file reading faster after first time ?

    Do you load these files from disk?

    I'd add some logic into the program loading all the images first, before displaying them. this will reduce the time taking to show the pics quite a lot.

    I would load all the associated images into an array of images, then just load each indexed array item as needed.

    Does that make sense?

  3. #3
    Join Date
    Jan 2012
    Posts
    7

    Re: bmp file reading faster after first time ?

    yes im loading them from the hard disc
    I get about 4GB of .bmps for 5minute of video so loading it all in memory would take way too much RAM

    I found a way to overcome the loading time problem for my VB prog, I just reduced the image size so now in 400x400 the images load almost as fast as if they were preloaded. I just split the 800x800 image into 4 400x400, it looked better with 800x800 but you can still select which part you want to see.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: bmp file reading faster after first time ?

    I would say the speed issue would be related to the way windows handles memory. Once you have loaded the bitmap it will stay in memory or in the page file for a while so a reload will be much faster than the initial load. The same thing happens with many programs. Initially when you load a program it may take a few seconds but if you close that program and open it again it may be almost instant.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: bmp file reading faster after first time ?

    I put a deck of cards in as Images in the Resource File. Loads instantly
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: bmp file reading faster after first time ?

    4GB of .bmps...Time to switch to a lighter format. How about png ? It is till good even if heavier of jpeg or gif (they both lose too much quality)
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: bmp file reading faster after first time ?

    Used .PNG's
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: bmp file reading faster after first time ?

    I would say that the time difference is due to the Hard Drive cache. Once you load a file, your hard drive will cache that information in memory for faster access later. This is why if you open the folder with explorer, and explorer builds the thumbnails, that they load fast from then on. Explorer has already opened and read the entire file from disk to build the thumbnail. So the hard drive has cached it and now you application gets the benefit of the file being cached.

    It is the same thing for writing, the cache on the hard drive takes everything into the cache, then does the physical write to disk. So your first 500, fills up the cache, and new ones will get accepted as old ones are written out.

  9. #9
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow Re: bmp file reading faster after first time ?

    There are a few tricks you can use to speed this up. I would start with the drawing. You can obviously gain much greater performance by using DirectX and/or WPF/WinRT, but you can also speed things up in the GDI+ world too. See below:

    Code:
    Public Class Form1
        Friend Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
            SetStyle(ControlStyles.UserPaint, True)
            SetStyle(ControlStyles.AllPaintingInWmPaint, True)
            Me.UpdateStyles()
    
        End Sub
    
        Private WithEvents _timer As New Timer()
    
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            _timer.Interval = 2000
            _timer.Start()
        End Sub
    
        Private Sub _timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _timer.Tick
            Me.Invalidate(New Rectangle(0, 0, 400, 400))
        End Sub
    
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    
            'You would progress through frames here
            e.Graphics.DrawImage(YourImageHere, 0, 0, 400, 400)
    
        End Sub
    
    
    End Class
    Next, as previously mentioned, you should be working on some type of pre-load cache solution. Kind of like how your video player loads ahead (buffers) while you watch.

    Alternatively/Additionally, you could look at using WeakReferences as a poor man’s cache solution, and just load them all up front.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured