[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 0/1] RFC: add ssh_buffer_ensure_allocated
[Thread Prev] | [Thread Next]
- Subject: Re: [PATCH v2 0/1] RFC: add ssh_buffer_ensure_allocated
- From: Pino Toscano <ptoscano@xxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 09 Jul 2018 09:56:52 +0200
- To: libssh@xxxxxxxxxx
On Friday, 6 July 2018 15:32:55 CEST you wrote: > 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. Almost: ssh_buffer_allocate() expands the size of the buffer of the specified size, growing the buffer if needed. ssh_buffer_ensure_allocated() makes sure the internal buffer has at least the specified size, growing it if smaller, and doing nothing otherwise. Yes, they are similar, but they cannot be used in the same way. -- Pino Toscano
Attachment:
signature.asc
Description: This is a digitally signed message part.
Re: [PATCH v2 0/1] RFC: add ssh_buffer_ensure_allocated | Andreas Schneider <asn@xxxxxxxxxxxxxx> |