[rrd-developers] RRDs.xs malloc to multi-dimensional array

Alexandre CHERIF alexandre at neutrinos.org
Tue Aug 13 14:53:47 MEST 2002


Hi,

i've got poor performance using RRDs::fetch with perl. 

here is the problem. When you try to fetch value for a rdd file with then command line, then rrdtool
malloc the entire space of memory needed. but when using the perl-shared module is malloc the first
rows of data, then for each rows malloc the column needed. it's pretty expensive in memory and cpu
usage. the possible solution it to malloc the array in one time. since my knowledge of perl module
programming is near from zero. does anybody need how to do

actual RRDs.xs
#define rrdcode(name) \
                argv = (char **) malloc((items+1)*sizeof(char *));\
                argv[0] = "dummy";\
                for (i = 0; i < items; i++) { \
                    STRLEN len; \
                    char *handle= SvPV(ST(i),len);\
                    /* actually copy the data to make sure possible modifications \
                       on the argv data does not backfire into perl */ \
                    argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
                    strcpy(argv[i+1],handle); \
                } \

as you can see malloc is on the loop, and there is this dummy value on argv[0]

my solution **which doesn't work** but that might be helpful

#define rrdcode(name) \
                argv = (char **) malloc((items+1)*sizeof(char *));\
                aRgV[0] = (char *)malloc((items+1) * (30+1) * sizeof(char)); \
                for (i = 0; i < items; i++) { \
                    STRLEN len; \
                    char *handle= SvPV(ST(i),len);\
                    /* actually copy the data to make sure possible modifications \
                       on the argv data does not backfire into perl */ \
                    argv[i+1] = aRgV[0] + ((i+1) * 31); \
                    strcpy(argv[i+1],handle); \
                } \

i've fixed the len of (*handle) to 31 , but i don't know what is the value. some variable are uppercase
in case some would diff this bad code in his own.

that's all.

Regards
-- 
Alexandre
==
Don't try and use this release for anything useful. We have made every effort to ensure that all
bits in this package are either 0 or 1. However, these bits may not be in the correct order and proportion. 
==

--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-developers mailing list