[Botan-devel] clearing pipe messages
mahkamov at gmail.com
Wed Dec 14 05:12:15 EST 2005
The problem is that the memory usage of my application starts to grow
if i reuse the Pipe. May be there's some mistake on my side. Here's
the piece of code I use:
class TBCryptoModule : public ICryptoModule
void __fastcall prepare();
void __fastcall Encrypt(TData* data);
void __fastcall TBCryptoModule::prepare()
m_enc_pipe = new Botan::Pipe(m_enc = Botan::get_cipher(enc_name, key, iv, Botan::ENCRYPTION));
m_dec_pipe = new Botan::Pipe(m_dec = Botan::get_cipher(dec_name, key, iv, Botan::DECRYPTION));
void __fastcall TBCryptoModule::Encrypt(TData* data)
// the IV is calculated and updated here
int i = m_enc_pipe->remaining();
When i call Encrypt() for the first time the code works fine and data
is (probably) encrypted. The second time the Botan::Pipe::remaining()
returns 0. No exception is thrown and the memory starts to grow.
Thanks in advance
Wednesday, December 14, 2005, 2:20:31 AM, you wrote:
> Hi Muzaffar,
> Reading the previous message out removes it from memory (reading is
> destructive; Pipe doesn't keep a copy), so this shouldn't be a problem. There
> is still a small overhead, the empty SecureQueue* object, but that should be on
> the order of three pointers per message.
> My first inclination would be that the right way to go about dealing with this
> overhead, if it's actually a problem, is to delete/NULL out empty SecureQueue
> objects stored in this->messages and then (re-)initialize them lazily. This
> would be a lot cleaner, and would not require any explicit actions on the part
> of the user.
> Are you seeing substantially more overhead in your application than the above
> would suggest? If so, could you please post a testcase for me to poke at?
> On Tue, Dec 13, 2005 at 03:50:22PM +0500, Muzaffar Mahkamov wrote:
>> Is it possible to clear all the messages of Pipe and reuse it several
>> times? I need to encrypt/decrypt large amounts of data in small chunks
>> and constructing Pipe with calling get_cipher with lookups each time
>> is a pretty expensive operation.
>> set_default_msg() is inacceptable for this case since it does not
>> remove the previous messages and doesn't free the memory.
>> I want to modify the Pipe class by adding the following function:
>> void Pipe::clear_messages()
>> throw Invalid_State("Pipe cannot be modified while it is locked");
>> for(u32bit j = 0; j != messages.size(); j++)
>> delete messages[j];
>> locked = false;
>> Would it be sufficient for reusing the pipe or there are some internal
>> states/flags that also must be cleared?
>> Thanks in advance,
>> botan-devel mailing list
>> botan-devel at randombit.net
> botan-devel mailing list
> botan-devel at randombit.net
Muzaffar mailto:mahkamov at gmail.com
More information about the botan-devel