Review Board 1.7.16

Optimizations to the stringfields API

Review Request #165 - Created Feb. 17, 2009 and submitted

Kevin Fleming
This patch provides a number of optimizations to the stringfields API, focused around saving (not wasting) memory whenever possible. Thanks to Mark Michelson for inspiring this work and coming up with the first two optimizations that are represented here:


- Cleanup of some code, fix incorrect doxygen comments

- When a field is emptied or replaced with a new allocation, decrease the amount of 'active' space in the pool it was held in; if that pool reaches zero active space, and is not the current pool, then free it as it is no longer in use

- When allocating a pool, try to allocate a size that will fit in a 'standard' malloc() allocation without wasting space

- When allocating space for a field, store the amount of space in the two bytes immediately preceding the field; this eliminates the need to call strlen() on the field when overwriting it, and more importantly it 'remembers' the amount of space the field has available, even if a shorter string has been stored in it since it was allocated

- Don't automatically double the size of each successive pool allocated; it's wasteful
Tested with basic SIP calling between two phones that registered to Asterisk; no problems seen.
Review request changed
Updated (Feb. 18, 2009, 9:11 a.m.)
  • Compile testing only, so far.

    Tested with basic SIP calling between two phones that registered to Asterisk; no problems seen.
Updated to use a typedef per Russell's suggestion, add some more code documentation, and fixed two bugs.
Ship it!
Posted (March 30, 2009, 6:58 a.m.)
This review certainly passes my scrutiny and it also passes the test that I submitted in a separate review request. Ship this puppy!

I'm going to withhold closing/merging the string field test until I've made it a bit more generic. Right now it is specifically testing the changes made here. runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to