Results 1 to 2 of 2

Thread: [2005] Memory issue???

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    top of the mountain
    Posts
    234

    Question [2005] Memory issue???

    Hi,
    please look at this code, it's very simple console application, just read some binary file from hard drive and convert it to ToBase64String so it can be sent by email. Problem with this code is that when it read file with size of 36Mb program allocate about 500Mb ?!? Can sombody tell me why, what I'm missing?

    Code:
    Imports System.IO
    Imports System.Text
    
    
    Module Module1
    
        Sub Main()
             Dim fs As FileStream = File.OpenRead("c:\test")
             Dim base64String As New StringBuilder(Convert.ToInt32((fs.Length + 1000)))
             Dim Header As New StringBuilder(Convert.ToInt32((fs.Length + 1000)))
             Dim binaryData() As Byte = New [Byte](fs.Length) {}
             Dim bytesRead As Long = fs.Read(binaryData, 0, CInt(fs.Length))
             fs.Close()
             base64String.Append(System.Convert.ToBase64String(binaryData, 0, binaryData.Length))
    
             Dim i As Integer
    
             While i < base64String.Length
                Dim nextchunk As Integer = 100
                If base64String.Length - (i + nextchunk) < 0 Then
                   nextchunk = base64String.Length - i
                End If
                Header.Append(base64String.ToString(i, nextchunk))
                Header.Append(ControlChars.Cr + ControlChars.Lf)
                i += nextchunk
             End While
    
             Console.ReadLine()
        End Sub
    
    End Module
    thanks j

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Memory issue???

    Did you debug the code? If you step through it a line at a time you should be able to narrow it down at the very least. Debugging does not consist of simply gazing at your code and hoping something looks broken. Just like a mechanic with a car, you have to run it and watch it in action.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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