-
July 14th, 2013, 01:02 PM
#1
out of memory exception reading large files.
I am encrypting and storing 2 files in 1 and extracting it. Application like iExpress.or winzip or win rar.My code works but for big files it gives error out of memory exception
encrypting and storing section =
byte[] buffer = Properties.Resources.stub;
string sp = "[SPLITTER]";
File.WriteAllBytes(sfd.FileName, buffer);
byte[] file1 = Secure(File.ReadAllBytes(textBox1.Text));
byte[] file2 = Secure(File.ReadAllBytes(textBox2.Text));
File.AppendAllText(sfd.FileName, sp + Convert.ToBase64String(file1) + sp + F1 + sp + Convert.ToBase64String(file2) + sp + F2);
and here extracting and decrypting
string source = File.ReadAllText(Application.ExecutablePath);
string[] stringSeparators = new string[] { "[SPLITTER]" };
string[] Drop = source.Split(stringSeparators, StringSplitOptions.None);
byte[] file1 = Unsecure(Convert.FromBase64String(Drop[1]));
byte[] file2 = Unsecure(Convert.FromBase64String(Drop[3]));
File.WriteAllBytes(TempDir + Drop[2], file1);
File.WriteAllBytes(TempDir + Drop[4], file2);
-
July 15th, 2013, 02:50 AM
#2
Re: out of memory exception reading large files.
What does the secure function do?
A couple of tips...
Rather than using raw arrays, try using collections. Next try reading the files line by line (and clean up the memory or reuse the memory for each line).
Use IDisposable and a using block so that memory gets freed when you leave the scoping block.
-
July 15th, 2013, 06:09 AM
#3
Re: out of memory exception reading large files.
Originally Posted by Arjay
What does the secure function do?
A couple of tips...
Rather than using raw arrays, try using collections. Next try reading the files line by line (and clean up the memory or reuse the memory for each line).
Use IDisposable and a using block so that memory gets freed when you leave the scoping block.
secure function encrypting the bytes (data/files).
yes good sujection about collection or small chunks but dont know who to loop it or .... can you give me short code for that
and yes here is my secure function
public byte[] Secure(byte[] Data)
{
using (RijndaelManaged SA = new RijndaelManaged())
{
SA.IV = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7 };
SA.Key = new byte[] { 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
return SA.CreateEncryptor().TransformFinalBlock(Data, 0, Data.Length);
}
-
July 18th, 2013, 05:31 PM
#4
Re: out of memory exception reading large files.
pleae help me about it.reply me coders
-
July 20th, 2013, 01:14 PM
#5
Re: out of memory exception reading large files.
You already got some tips from arjay. Don't use File.ReadAllBytes() read the file in chunks or line by line instead.
-
July 21st, 2013, 10:56 AM
#6
Re: out of memory exception reading large files.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|