Here is a gist of what I am trying to do. I store files in SQL table. The table is large with 400 records but each record stores the file archive and their size is approximately 100MB each. Recently, we had to change our encryption key.So I am writing a threaded ( 5 threads ) code to decrypt using the legacy key and then encrypt using the new key.This is what each thread does
struct DataToReencrypt
{
int id;
string data;
}
vector<DataToReencrypt> results;
// database open
SELECT ID,FileData From Files WHERE ID BETWEEN 1 AND 80 // 81-160 and so on.
// database connection close
// database connection open
for(int i=0;i<results.size();i++ ) // results contain the result of the above query.
{
string decrypted = LegacyDecryption(results[i].FileData);
string encrypted = NewEncryption(decrypted);
UPDATE Files SET FileData = encrypted WHERE ID = results[i].ID;
}
// database connection close
The problem is when I am trying to do this,I get this C++ bad_memory alloc exception and also SQL Memory alloc exception. While I was reading through the bad_memory alloc exception I read C++ throws it when the compiler cannot allocate new memory. Just in case if this helps, I am running this on a system with 6GB RAM ( I have to make this work in 6GB RAM as it is the minimum our product supports) and while this process runs the sqlserver.exe process takes almost close 4GB of RAM space. Please help with any problem with this approach or anyways that it could be improved.
Aucun commentaire:
Enregistrer un commentaire