Click here to Skip to main content
15,913,221 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trial version of a Software Pin
papadimitriou15-Apr-08 4:32
papadimitriou15-Apr-08 4:32 
General[Message Deleted] Pin
pyde15-Apr-08 1:21
pyde15-Apr-08 1:21 
GeneralRe: problem with a modalPopUpExtender Pin
Christian Graus15-Apr-08 1:22
protectorChristian Graus15-Apr-08 1:22 
GeneralRead binary files with Progressbar Pin
Ian Uy15-Apr-08 1:18
Ian Uy15-Apr-08 1:18 
GeneralRe: Read binary files with Progressbar Pin
Christian Graus15-Apr-08 1:20
protectorChristian Graus15-Apr-08 1:20 
GeneralRe: Read binary files with Progressbar Pin
Ian Uy15-Apr-08 1:26
Ian Uy15-Apr-08 1:26 
GeneralRe: Read binary files with Progressbar Pin
Christian Graus15-Apr-08 1:33
protectorChristian Graus15-Apr-08 1:33 
GeneralRe: Read binary files with Progressbar Pin
Ian Uy15-Apr-08 3:00
Ian Uy15-Apr-08 3:00 
Thanks.

Using the given method on the bottom of the page, I can successfully read a file. But somehow, reading a file that is too large (350mb) gives me an Out of Memory exception.

Is this a problem with the code?

public static byte[] ReadFully (Stream stream, int initialLength)<br />
{<br />
    // If we've been passed an unhelpful initial length, just<br />
    // use 32K.<br />
    if (initialLength < 1)<br />
    {<br />
        initialLength = 32768;<br />
    }<br />
    <br />
    byte[] buffer = new byte[initialLength];<br />
    int read=0;<br />
    <br />
    int chunk;<br />
    while ( (chunk = stream.Read(buffer, read, buffer.Length-read)) > 0)<br />
    {<br />
        read += chunk;<br />
        <br />
        // If we've reached the end of our buffer, check to see if there's<br />
        // any more information<br />
        if (read == buffer.Length)<br />
        {<br />
            int nextByte = stream.ReadByte();<br />
            <br />
            // End of stream? If so, we're done<br />
            if (nextByte==-1)<br />
            {<br />
                return buffer;<br />
            }<br />
            <br />
            // Nope. Resize the buffer, put in the byte we've just<br />
            // read, and continue<br />
            byte[] newBuffer = new byte[buffer.Length*2];<br />
            Array.Copy(buffer, newBuffer, buffer.Length);<br />
            newBuffer[read]=(byte)nextByte;<br />
            buffer = newBuffer;<br />
            read++;<br />
        }<br />
    }<br />
    // Buffer is now too big. Shrink it.<br />
    byte[] ret = new byte[read];<br />
    Array.Copy(buffer, ret, read);<br />
    return ret;<br />
}


It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

QuestionPDF to HTML conversion Pin
cincy15-Apr-08 1:06
cincy15-Apr-08 1:06 
GeneralRe: PDF to HTML conversion Pin
Christian Graus15-Apr-08 1:21
protectorChristian Graus15-Apr-08 1:21 
QuestionCaramel - code generator: Anyone interested in joining? Pin
Roger Alsing15-Apr-08 1:01
Roger Alsing15-Apr-08 1:01 
GeneralC# SQL date issue Pin
AJ du Plessis15-Apr-08 0:42
AJ du Plessis15-Apr-08 0:42 
GeneralRe: C# SQL date issue Pin
Christian Graus15-Apr-08 1:01
protectorChristian Graus15-Apr-08 1:01 
GeneralRe: C# SQL date issue Pin
Harvey Saayman15-Apr-08 1:14
Harvey Saayman15-Apr-08 1:14 
GeneralRe: C# SQL date issue Pin
J4amieC15-Apr-08 1:19
J4amieC15-Apr-08 1:19 
GeneralRe: C# SQL date issue Pin
Harvey Saayman15-Apr-08 22:26
Harvey Saayman15-Apr-08 22:26 
General[Message Deleted] Pin
sarilee15-Apr-08 0:02
sarilee15-Apr-08 0:02 
GeneralRe: combobox in datagrid Pin
Christian Graus15-Apr-08 0:14
protectorChristian Graus15-Apr-08 0:14 
GeneralRe: combobox in datagrid Pin
sarilee15-Apr-08 0:48
sarilee15-Apr-08 0:48 
GeneralRe: combobox in datagrid Pin
Christian Graus15-Apr-08 0:50
protectorChristian Graus15-Apr-08 0:50 
GeneralRe: combobox in datagrid Pin
sarilee15-Apr-08 1:15
sarilee15-Apr-08 1:15 
Generaltemplates in datagrid Pin
sarilee14-Apr-08 23:45
sarilee14-Apr-08 23:45 
GeneralRe: templates in datagrid Pin
Christian Graus14-Apr-08 23:53
protectorChristian Graus14-Apr-08 23:53 
GeneralStreamWriter Pin
George_George14-Apr-08 23:44
George_George14-Apr-08 23:44 
GeneralRe: StreamWriter Pin
N a v a n e e t h15-Apr-08 0:25
N a v a n e e t h15-Apr-08 0:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.