Handling large files in encryption prog

B

BrianJones

I'm currently writing an encryption program designed to read in a file (and
encrypt it) by splitting it in to 128 byte block segments and encrypting
each segment iteratively. The problem is is that it works fine up to sizes
of approx 8.5MB (albeit the program slows down throughout the process) and
then crashes at 8.5 leaving me to have to reboot my computer (linux).

Here is the pseudo-code:

whilst not eof
{
read in 128 bytes from file, stick in to inBytes[]
encrypt inBytes[], stick reult in to outBytes[];
write outBytes to disk[];

iterate put stream pointer by 128;
iterate get stream pointer by 128;
}// end of encryption process

delete[] inBytes;delete[] outBytes;

Do you think its a memory (de)allocation issue with inBytes and outBytes. If
so, does any one have any suggestions how I can sort it out?

Thanks
Ben
 
K

Karl Heinz Buchegger

BrianJones said:
I'm currently writing an encryption program designed to read in a file (and
encrypt it) by splitting it in to 128 byte block segments and encrypting
each segment iteratively. The problem is is that it works fine up to sizes
of approx 8.5MB (albeit the program slows down throughout the process) and
then crashes at 8.5 leaving me to have to reboot my computer (linux).

Here is the pseudo-code:

pseudo code is of no use in diagnosing a problem in your real code.

The fact that your program slows down is an inidcation that something
is wrong. My guess would be: the encrypt function allocates memory which is
never released. Thus memory leaks get bigger over time and eventually your
program runs out of memory. But that's just a guess.
 
J

John Harrison

BrianJones said:
I'm currently writing an encryption program designed to read in a file (and
encrypt it) by splitting it in to 128 byte block segments and encrypting
each segment iteratively. The problem is is that it works fine up to sizes
of approx 8.5MB (albeit the program slows down throughout the process) and
then crashes at 8.5 leaving me to have to reboot my computer (linux).

Here is the pseudo-code:

whilst not eof
{
read in 128 bytes from file, stick in to inBytes[]
encrypt inBytes[], stick reult in to outBytes[];
write outBytes to disk[];

iterate put stream pointer by 128;
iterate get stream pointer by 128;
}// end of encryption process

delete[] inBytes;delete[] outBytes;

Do you think its a memory (de)allocation issue with inBytes and outBytes. If
so, does any one have any suggestions how I can sort it out?

Well I wonder why you are allocating memory at all, 128 bytes is small
enough that you should just declare those arrays on the stack.

What does

iterate put stream pointer by 128;
iterate get stream pointer by 128;

mean? You are reading and writing files sequentially, there is no need to
adjust the get or put positions. If that is what you are doing then I would
think that could cause a big slow down in your program.

If that doesn't help I suggest you post some real code.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,235
Latest member
Top Crypto Podcasts_

Latest Threads

Top