title: Very large String into Byte Array
body: <p>I have an XML file which result from the export of a database (Oracle 11g Unicode) table.
  This table has a BLOB field which represent a file. The file could be a very large one.</p>
  
  <p>So in the case where I have a very large file a get in the XML a very large string representation of that file.</p>
  
  <p>I have to get the bytes of this string in order to insert the file in another database instance.</p>
  
  <p>A this point the XML is charged and i have then a string representing the file.</p>
  
  <p>What I've done is this:</p>
  
  <p><code>Encoding.Unicode.GetBytes(stringFileRepresentation);</code></p>
  
  <p>But I'm getting an <code>OutOfMemoryException</code>.</p>
  
  <p>If I do this:</p>
  
  <p><code>Encoding.Unicode.GetBytes(stringFileRepresentation.ToCharArray());</code></p>
  
  <p>I get also an <code>OutOfMemoryException</code>.</p>
  
  <p>I tried too to do this before decoding the string:</p>
  
  <pre><code>var chars = stringFileRepresentation.ToCharArray();
  Encoding.Unicode.GetBytes(chars);
  </code></pre>
  
  <p>And I getting the <code>OutOfMemoryException</code> when calling <code>ToCharArray()</code>.</p>
  
  <p>So I guess is a problem when <em>processing</em> the string.</p>
  
  <p>Then I'm trying the following method that I found <a href="https://stackoverflow.com/a/10380166/2776550">here</a> event if I'm not sure I have to conservate the encoding of the string:</p>
  
  <pre><code>byte[] bytes = new byte[str.Length * sizeof(char)];
  Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
  </code></pre>
  
  <p>But I'm getting also an <code>OutOfMemoryException</code> in instantiating the <code>bytes</code> variable.</p>
  
  <p>Now, I ran <code>OutOfOptions</code> and I don't know what to do.</p>