<br><font size=2 face="sans-serif">Frank,</font>
<br>
<br><font size=2 face="sans-serif">My impression is, that PHP-Mapscript
will face the mentioned problem also.</font>
<br>
<br><font size=2 face="sans-serif">And problably every swig-based Mapscript
will have it. I had a look on Python-Mapscript.</font>
<br>
<br><font size=2 face="Arial">I think for the sake of "backward compatibility"
the problem should be solved somehow. (For shure</font>
<br><font size=2 face="Arial">"individual allocation" would be
a solution ...)</font>
<br>
<br><font size=2 face="sans-serif">Benedikt</font>
<br>
<br><font size=2><tt>UMN MapServer Developers List <MAPSERVER-DEV@LISTS.UMN.EDU>
schrieb am 15.05.2006 14:53:40:<br>
<br>
> Benedikt Rothe wrote:<br>
> > <br>
> > Hi<br>
> > <br>
> > Sorry for posting in this list since I'm no mapserver-developer,
but I <br>
> > wonder wether RFC17 may break<br>
> > mapscript-applications, which hold pointers to mapserver-Objects.<br>
> > <br>
> > Example Java:<br>
> > - A Java-layerObj is created with "aMapObject.getlayer(1)".
This <br>
> > layerObj-instance holds a pointer<br>
> > into the Layer-Array of the aMapObject.<br>
> > - After this, a new layer is added to the webobject. The
layers-Array <br>
> > in the webObject could be reallocated<br>
> > by this action.<br>
> > - Therfore the existing pointer in the Java-layerObj could become
invalid.<br>
> > This could cause crashes.<br>
> > <br>
> > Did I oversee something?<br>
> > Benedikt<br>
> <br>
> Benedikt,<br>
> <br>
> Yikes, you are quite right. In fact whenever we actually end
up "growing"<br>
> the list of layers, classes or styles any old pointers could be invalidated.<br>
> I don't forsee this occuring too often in the mapserver core itself
because<br>
> it isn't common to keep pointers around. Instead it is layer/class/style<br>
> indexes that are normally kept over time.<br>
> <br>
> In other C/C++ contexts I would normally have my layers array as an
array of<br>
> pointers to individually allocated layerObj's. That way, reallocating
the<br>
> array of pointers would not cause the existing layerObj's to move.
But<br>
> because mapserver uses a direct array of layerObj's, reallocating
inevitably<br>
> means the need to move all the existing layers in memory (and similarly
for<br>
> other objects).<br>
> <br>
> I *suppose* we could move to individual allocations in mapserver as
well.<br>
> But I think this would cause a lot of changes in the code that would
make<br>
> the effort much bigger, as well as resulting in more memory fragmentation.<br>
> <br>
> There are lots of places in the code that do stuff like this:<br>
> <br>
> lp = &(map->layers[ map->layerorder[i]]);<br>
> <br>
> If we changed layers to be an array of layerObj pointers, this would
return<br>
> a pointer to the layerObj pointer, instead of the pointer to the layerObj<br>
> itself. So quite a bit of code would need to be touched.
This change,<br>
> within the mapserver core, should be relatively routine grunt work.
I'm not<br>
> sure if it would have a significant affect on mapscript or not. I
*think*<br>
> this change would be relatively invisible to mapscript once re-swigged
and<br>
> rebuilt.<br>
> <br>
> I think I would be willing to try and implement individual allocation
of<br>
> the layer/class/style objects if the developer would like to take
this<br>
> approach. The downside is that there is likely to be changes
required in<br>
> parts of MapServer I don't normally build (like specific data providers<br>
> and specific output drivers). There is also likely to be more
work required<br>
> in the swig bindings. Should I rewrite the RFC with this intent?<br>
> <br>
> To be clear, most of the RFC would remain the same, but something
like:<br>
> <br>
> layerObj *layers;<br>
> int numlayers; /* number of layers in mapfile */<br>
> int maxlayers;<br>
> <br>
> would become:<br>
> <br>
> layerObj **layers;<br>
> int numlayers; /* number of layers in mapfile */<br>
> int maxlayers;<br>
> <br>
> So "layers" is a pointer to an array of layerObj pointers.
When the map is<br>
> initialized each of the initial MS_MAXLAYERS layerObj would be individually<br>
> malloced, and initialized. when the msGrowMapLayers() function
needs to<br>
> grow the layers list it would reallocate the array of pointers larger,<br>
> and allocate some new layerObj's.<br>
> <br>
> Best regards,<br>
> -- <br>
> ---------------------------------------+--------------------------------------<br>
> I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@pobox.com<br>
> light and sound - activate the windows | http://pobox.com/~warmerdam<br>
> and watch the world go round - Rush | President OSGF,
http://osgeo.org<br>
</tt></font>