mp_init/mp_clear memory allocation
Ed Sutter
ed.sutter at alcatel-lucent.com
Tue Apr 16 04:24:46 WST 2013
Hi,
I started digging into the possibility of reducing the number of malloc/free
calls (by replacing small/quick fixed-size allocations with stack arrays),
and I think I found one that makes a substantial difference...
The call to mp_div_2d() in a loop inside the function
mp_to_unsigned_bin()...
If I create a version of mp_init() (call it mp_init_nomalloc() that does
not allocate
and then I put that small array on the stack in mp_div_2d(), I observed
a dramatic
decrease in the number of malloc/free calls (dropped from about 2100 to
about 550) for
a single session that simply connects and then exits.
This is tough to observe dynamically without a debuggable malloc (which
I have);
but its always possible that my diagnostics are off too; hence it would
be nice to get a second set of eyes looking at this to see if my
observation is
correct. If it is, then it would apply to any function that does both the
mp_init() and the matching mp_clear() in the same block of code.
New versions of libtomath/bn_mp_div_2d.c and bn_mp_init.c are attached
if someone has time to double check me.
Hopefully I won't realize my mistake immediately after I send this as I
did before and have to retract my statement!! :-(
Ed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bn_mp_init.c
Type: text/x-csrc
Size: 1490 bytes
Desc: not available
Url : http://lists.ucc.gu.uwa.edu.au/pipermail/dropbear/attachments/20130415/e6426434/attachment.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bn_mp_div_2d.c
Type: text/x-csrc
Size: 2481 bytes
Desc: not available
Url : http://lists.ucc.gu.uwa.edu.au/pipermail/dropbear/attachments/20130415/e6426434/attachment-0001.c
More information about the Dropbear
mailing list