Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hugh Memory Problem using DataGridView

Status
Not open for further replies.

eblattner

Programmer
Aug 10, 2000
33
Hey all. I have a problem displaying a binary file in a DataGridView control. This program is basically a binary editor/mapper for automotive PCM files. Loading the file in to the array is very fast (less than 5 seconds), displaying in the grid is slow (no biggie), but the biggest problem I have is memory usage.

The binary files I'm reading are either 512k or 1024k. I import a file into an array, then display it in the DataGridView. This is where the problem comes, for a 512k file, this program uses about 95 megs (over the memory it used just to run). If I skip loading the datagrid, it's fine.

Here is the code...

Code:
        ReDim BinaryFile(FileLength - 1)

        For i = 0 To FileLength - 1

            b += 1
            tmpByte = r.ReadByte
            BinaryFile(i) = tmpByte

            tmp_Str = Hex$(tmpByte)

            If tmp_Str.Length = 1 Then
                tmp_Str = "0" & tmp_Str
            End If

            DataGridView1.Rows(a).Cells(b - 1).Value = tmp_Str
            If b = 16 Then
                a += 1
                MyPosition = Hex$(a)
                If MyPosition.Length < 4 Then
                    Select Case MyPosition.Length
                        Case 1
                            MyPosition = "000" & MyPosition
                        Case 2
                            MyPosition = "00" & MyPosition
                        Case 3
                            MyPosition = "0" & MyPosition
                    End Select
                End If

                b = 0
                DataGridView1.Rows.Add()
                DataGridView1.Rows(a).HeaderCell.Value = MyPosition

            End If


        Next i

If I rem out the DataGridView lines and leave everything else in this routine alone, there is no memory problem.

I am lost as to what I am doing wrong, any help is appreciated. Thanks in advance :)
 
So how many rows do you get?

Use a collection and databind it to the datagridview.

Christiaan Baes
Belgium

"My new site" - Me
 
The grid is 16 columns by 65535 rows on a 512k file. All I need to do it display and edit the binary file, but the datagrid is the only way I know how to do this. I have seen other binary editors load the file VERY fast, but I assumed it's not loading the whole thing.

I'll try the colectionamd see how that works, it sounds like a good idea. I'm not sure exactly how, but I think I can figure it out.

 
Take a look at some of the 3rd party grids. Most of them have a feature called "virtual mode", where the grid calls you when it's time to display a cell. This way you don't load the entire grid up initially -- you just give it data when it calls your delegate.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
As suggested above (thanks Chrissie1), I read the binary file into a dataset with pretty good results. Load time was about 1/10th as long, and the memory used was greatly reduced.

Now the problem I'm having is setting the rows' caption. I need the row header to display the row number in hex (ie. 0000, 0001, 0002, A123 ect.) When I do this, the memory problem comes back :( 28 megs displaying the data in the datagridview, but it goes up to 112 megs just adding the row header.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top