Handling large files in encryption prog

Discussion in 'C++' started by BrianJones, Jul 23, 2004.

  1. BrianJones

    BrianJones Guest

    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
     
    BrianJones, Jul 23, 2004
    #1
    1. Advertising

  2. BrianJones wrote:
    >
    > 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.

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Jul 23, 2004
    #2
    1. Advertising

  3. "BrianJones" <> wrote in message
    news:cdqt0o$pvu$...
    > 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
     
    John Harrison, Jul 23, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    778
  2. boomer

    Large files handling

    boomer, Nov 9, 2003, in forum: XML
    Replies:
    1
    Views:
    374
    Andy Dingley
    Nov 10, 2003
  3. Michael

    Handling large files > 4 GB

    Michael, Jun 22, 2004, in forum: C++
    Replies:
    3
    Views:
    768
    Pete C.
    Jun 23, 2004
  4. -intl.com
    Replies:
    1
    Views:
    381
    Martin Gregorie
    Oct 22, 2006
  5. Robert Kochem
    Replies:
    1
    Views:
    376
    Arne Vajhøj
    Apr 29, 2010
Loading...

Share This Page