shapeObj buffer resize algorithm
Kovacs Baldvin
baldvin at CS.ELTE.HU
Wed Jul 27 10:21:37 EDT 2005
Hi!
I've attached a patch that makes the msAddLines variants to use
relocate, but without introducing the manual heuristic. I think
it is the reasonable solution...
Best regards,
Baldvin Kovacs
-------------------------
Below are the profiling results. For every test case 100 runs
were made and the results cumulated. All of them was compiled
with -O2 -pg
1. With this patch included:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
17.79 4.67 4.67 100 46.70 46.70 msImageCopyMerge
14.63 8.51 3.84 200 19.20 19.20 msImageInitGD
...
3.85 19.46 1.01 3120400 0.00 0.00 msAddLine
2. With the bufsize *= 2 heuristic:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
18.69 4.87 4.87 100 48.70 48.70 msImageCopyMerge
14.51 8.65 3.78 200 18.90 18.90 msImageInitGD
...
2.99 19.79 0.78 3120400 0.00 0.00 msAddLine
...
0.31 24.75 0.08 441600 0.00 0.00 msShapeObjIncBuffer
3. cvs version:
% cumulative self self total
time seconds seconds calls s/call s/call name
86.61 163.87 163.87 3120400 0.00 0.00 msAddLine
2.53 168.66 4.79 100 0.05 0.05 msImageCopyMerge
1.99 172.42 3.76 200 0.02 0.02 msImageInitGD
-------------- next part --------------
Index: mapprimitive.c
===================================================================
RCS file: /data2/cvsroot/mapserver/mapprimitive.c,v
retrieving revision 1.53
diff -u -r1.53 mapprimitive.c
--- mapprimitive.c 14 Jun 2005 16:03:34 -0000 1.53
+++ mapprimitive.c 27 Jul 2005 14:01:26 -0000
@@ -1,4 +1,4 @@
-/******************************************************************************
+ /******************************************************************************
*
* Project: MapServer
* Purpose: Implementations for rectObj, pointObj, lineObj, shapeObj, etc.
@@ -254,35 +254,27 @@
int msAddLine(shapeObj *p, lineObj *new_line)
{
int c;
- lineObj *extended_line;
/* Create an extended line array */
- if((extended_line = (lineObj *)malloc((p->numlines + 1) * sizeof(lineObj))) == NULL) {
+ p->line = (lineObj *)realloc(p->line, (p->numlines + 1) * sizeof(lineObj));
+ if( p->line == NULL ) {
msSetError(MS_MEMERR, NULL, "msAddLine()");
return(MS_FAILURE);
}
- /* Copy the old line into the extended line array */
- for (c= 0; c < p->numlines; c++)
- extended_line[c]= p->line[c];
-
/* Copy the new line onto the end of the extended line array */
- c= p->numlines;
- extended_line[c].numpoints = new_line->numpoints;
- if((extended_line[c].point = (pointObj *)malloc(new_line->numpoints * sizeof(pointObj))) == NULL) {
+ c = p->numlines;
+ p->line[c].numpoints = new_line->numpoints;
+ if((p->line[c].point = (pointObj *)malloc(new_line->numpoints * sizeof(pointObj))) == NULL) {
msSetError(MS_MEMERR, NULL, "msAddLine()");
return(MS_FAILURE);
}
- memcpy( extended_line[c].point, new_line->point,
+ memcpy( p->line[c].point, new_line->point,
sizeof(pointObj) * new_line->numpoints );
- /* Dispose of the old line */
- if(p->line) free(p->line);
-
/* Update the polygon information */
p->numlines++;
- p->line = extended_line;
return(MS_SUCCESS);
}
@@ -294,33 +286,25 @@
int msAddLineDirectly(shapeObj *p, lineObj *new_line)
{
int c;
- lineObj *extended_line;
/* Create an extended line array */
- if((extended_line = (lineObj *)malloc((p->numlines + 1) * sizeof(lineObj))) == NULL) {
+ p->line = (lineObj *)realloc(p->line, (p->numlines + 1) * sizeof(lineObj));
+ if( p->line == NULL ) {
msSetError(MS_MEMERR, NULL, "msAddLine()");
return(MS_FAILURE);
}
- /* Copy the old line into the extended line array */
- for (c= 0; c < p->numlines; c++)
- extended_line[c]= p->line[c];
-
/* Copy the new line onto the end of the extended line array */
c= p->numlines;
- extended_line[c].numpoints = new_line->numpoints;
- extended_line[c].point = new_line->point;
+ p->line[c].numpoints = new_line->numpoints;
+ p->line[c].point = new_line->point;
/* strip points reference off the passed in lineObj */
new_line->point = NULL;
new_line->numpoints = 0;
- /* Dispose of the old line */
- if(p->line) free(p->line);
-
/* Update the polygon information */
p->numlines++;
- p->line = extended_line;
return(MS_SUCCESS);
}
More information about the mapserver-dev
mailing list