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