I have written (with some pointers from Nick Ing-Simmons -- thanks Nick), some
code intended to read in large (~200+Mb)files. The relevant part of the XS of
the code read like this:
AV *AoA; /* Array of strings */ int param_size; int paramater_count = 0; char *bufferX, *bufferY; while (!feof(file)){ /* read in paramater name */ if(!feof(file)) { fread(¶m_name, PARAM_NAME, 1, file); /*PARAM_NAME is define'd.*/ /* now get size of array */ fread(¶m_size, sizeof(int),1,file); AoA = newAV(); av_extend(AoA, 3); av_store(AoA, 0, newSViv(param_size); bufferX = (char*)malloc(sizeof(double) *param_size); bufferY = (char*)malloc(sizeof(double) *param_size);
numbersX = newSVpv("",0); numbersY = newSVpv("",0);
SvGROW(numbersX, sizeof(double)*param_size); SvGROW(numbersY, sizeof(double)*param_size);
/* read in the array of doubles */ fread(bufferX, sizeof(double)*param_size, 1,file); fread(bufferY, sizeof(double)*param_size, 1,file);
/* copy them to the SV -- this means they will need to be*/ /* unpacked later */ sv_catpvn(numbersX, bufferX, sizeof(double)*param_size); sv_catpvn(numbersY, bufferY, sizeof(double)*param_size);
av_store(AoA, 1, numbersX); av_store(AoA, 2, numbersY);
XPUSHs(sv_2mortal(newSVpv,param_name,strlen(param_name))); XPUSHs(sv_2mortal(newRV_noinc(SV*)AoA)); paramater_count++; } } fclose(file); XSRETURN((paramater_count *2));
My problem is that I don't know if this is the best/fastest way to do this, and
I don't know if I am leaking memory. Can anyone offer some pointers?
-Thanks in advance,
-Doug Brann
_________________________________________________________________
Take advantage of our best MSN Dial-up offer of the year � six months @$9.95/month. Sign up now! http://join.msn.com/?page=dept/dialup
