none
SQLDataReader.GetBytes and memory consumption RRS feed

  • Question

  • Hi,

    I have following code to read the file bytes from database:

     

     1  long size = reader.GetBytes(0, 0, null, 0, 0);
     2  bytes = new byte[size];
     3  long lastPosition = 0;
     4  while (lastPosition < bytes.Length)
     5  lastPosition += reader.GetBytes(0, lastPosition, bytes, 0, bytes.Length);
    
    

     

    At line #1 per documentation here (see remarks) there is no data read when the buffer parameter is null. But still the memory footprint is going up and moreover it is going up by 2 folds. I am trying to download a file of 181 meg and i expect memory should go up by 181 meg (-/+ few megs) but it is going up by around 350 meg. When i check the size variable (line #1) value it is same as i expected, 181 meg. Not sure whats going on here. Also at line #5 it is the same behavior, memory going up by 2 folds. (i am watching Private working Set in Task manager)

    I am using framework 3.5

    Update

    Call to reader.GetBytes makes 2 copies of the data we requested from, verified using reflecter as well as loaded the base class symbols and verified. Therefore, this makes the memory footprint jump up by double at line #1. Is there a better way to read binary data from SQL DB (2005 and 2008)?

     

    Thanks

     

     



    • Moved by Larcolais Gong Wednesday, March 23, 2011 8:53 AM (From:Visual C# General)
    • Changed type Santosh BSK Wednesday, March 23, 2011 4:01 PM
    • Edited by Santosh BSK Wednesday, March 23, 2011 10:05 PM
    • Moved by KJian_ Thursday, March 24, 2011 9:18 AM (From:SQL Server Data Access)
    Wednesday, March 23, 2011 1:17 AM

Answers

All replies