[rrd-developers] rrd_calc and avoid repeated memory allocations/initial setups

Martin Sperl rrdtool at martin.sperl.org
Tue May 6 15:59:00 CEST 2014


Hi!

It seems as if there is no easy means to store extra data for the whole life-time of the
rpn_calc loop.

The reason why I ask is because I am implementing the predictperc function, which is 
similar to predict and predictsigma but it gives the X percentile.

For this I need to order the data (depending on arguments maybe 50-60 floats),
which means allocating memory (the exactly same amount for every time rpn_calc gets called)
to keep all those values sorted to find the correct percentile.

Unfortunately the way rrd_calc works, there is no data that is kept between calculations,
to avoid the repeated create/teardowns of this structures...

Seems as if an "easy" way would be enhancing rpnp_t by adding this this:
void *extra; /* extra data used during setup */
void (*free_extra)(void *); /* a function used to free the extra structure... 
			     * - if null, then a "normal free" is done */

and some code in rpnstack_free to call the "free" functionpointer with the argument of extra.
(or free directly if the pointer is NULL)

So would something like the above be acceptable?

Thanks,
	Martin


More information about the rrd-developers mailing list