On Wednesday, 27 June 2018 14:10:25 CEST Pino Toscano wrote:
> Hi,
>
> while profiling libssh, I noticed that in different places ssh_buffer's
> were realloc'ed more than once during their lifetime. Since in few cases
> the amount of data is known in advance, I added a small helper to make
> sure the internal allocated buffer will be large enough to contain all
> the data needed. Of course, this is just an optimization to be used when
> an amount is known, otherwise there will be an extra allocation.
>
> The downside is that each call to ssh_buffer_guarantee_allocated has a
> minimal knowledge of the internals of ssh_buffer, e.g. for a string (the
> value for its size, then the data of the string itself). Also, a
> better/shorter name is welcome too.
>
> An additional usage for this helper IMHO can be ssh_buffer_pack_va,
> which could interate once more at the beginning to determine the amount
> of data that will be added.
There is a new ssh_buffer_allocate() which seems to implement the same.
Andreas
--
Andreas Schneider [email protected]
GPG-ID: 8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D