shapeObj buffer resize algorithm

Kovacs Baldvin baldvin at CS.ELTE.HU
Wed Jul 27 06:50:55 EDT 2005

> I am somewhat concerned by your optimization because it now means
> anywhere that creates a local lineObj needs to remember to 
> properly initialize the bufsize array.  You may have found and updated
> everything in the core mapserver code properly, but are you sure you
> got all occurances in the mapscript bindings, utility programs and so 
> forth?  Because of MapServer's habit of making core structures

Now I've checked to subdirectories. Yes, I'm pretty sure that everything
in the code tree is OK with the bufsize. Not regarding my mistakes :))
However, continue reading... :)

> My take is that we should only be taking this risk if we are reasonly
> convinced that this is a significant optimization in fairly common
> circumstances.   Furthermore, I think we should check if use of realloc()
> does or doesn't give similar benefits on Linux and win32. 

Here are some results: 

:: 100 runs, measured the real time spent, for
:: the following configurations:
:: -O2, realloc, bufsize *= 2
::   Average: 0.7107
::   Standard deviation: 0.046
:: -O2, realloc, bufsize += 1
::   Average: 0.7137
::   Standard deviation: 0.038
:: -O2, cvs version:
::   Average: 0.7855
::   Standard deviation: 0.043

Interesting though, that if the very same optimization would be in
effect in the c library, why are the first two not the same??
Maybe the answer is: no, that optimization is not quite in there,
but the memmove operations are a lot more processor-close and
hence efficient than the for{} cycle being in the cvs version.

Whatever: changing to realloc is definitely justified. If the project
was mine, I thing I'd change to bufsize also (however, I don't know
how big and how many code trees do you know are out there that are
not only using mapserver through its interfaces, but are linking

I think I'll also do some profilings for the cases up there.

Best regards,
Baldvin Kovacs

More information about the mapserver-dev mailing list