Date: | 2006/05/12 |
---|---|
Author: | Frank Warmerdam, with edits from Daniel Morissette and Umberto Nicoletti |
Contact: | warmerdam at pobox.com, dmorissette at mapgears.com, umberto.nicoletti at gmail.com |
Last Edited: | 2007/07/18 |
Status: | Adopted (2007/07/18) - Implementation completed (2007/07/23) |
Version: | MapServer 5.0 |
Id: | $Id: ms-rfc-17.txt 8278 2008-12-23 21:34:31Z hobu $ |
Modify the MapServer core libraries so that lists of layers, classes and styles are dynamic, not fixed to compile limits MS_MAXCLASSES, MS_MAXSTYLES, MS_MAXLAYERS and MS_MAXSYMBOLS.
Change symbolSetObj so that this:
int numsymbols;
symbolObj symbol[MS_MAXSYMBOLS];
becomes:
int numsymbols;
int maxsymbols;
symbolObj **symbol;
Add the following function to ensure there is at least one free entry in the symbol array in the symbolSetObj. This function will only grow the allocated array of pointers if needed (if maxsymbols == numsymbols) and will then allocate a new symbolObj if symbol[numsymbols] == NULL. The new entries in the array will be set to NULL and the new symbolObj[numsymbols] will be all set to zero bytes.
symbolObj *msGrowSymbolSet( symbolSetObj * );
map.h
mapfile.c
mapsymbol.c
mapdraw.c
mapobject.c
mappluginlayer.c
layerobject.c
mapogcsld.c
classobject.c
mapscript/swiginc/layer.i
mapscript/swiginc/class.i
mapscript/swiginc/style.i
None.
Python unit test entries will be added to exceed the builtin maximums for all of layers, classes, styles and symbols. An msautotest entry with a large number of classes will also be added.
Vote completed on 2007-07-19:
+1 from DanielM, SteveL, FrankW, SteveW, UmbertoN, TamasS, AssefaY
Answer: the implementation adopted with MS RFC 24: Mapscript memory management tries to save memory by only allocating the number of layers that are effectively needed. A map with 5 layers will allocate exactly 5 layers, a map with 50 layers will allocate 50, and so on up to the hard-coded limit of MS_MAX_LAYERS. This is also true for classes and style.
The arrays of pointers are for obvious reasons always allocated to MS_MAX_LAYERS size, but memory usage is reduced anyway because arrays of pointers are much smaller that arrays of structs. This represents a substantial change from before, when MS_MAX_LAYERS blank layers where always allocated causing a sure waste of memory in small maps.
MS RFC 17: Dynamic Allocation of layers, styles, classes and symbols should then invoke the various msGrow*() methods to grow the arrays when numlayers == maxlayers-1. I’d suggest to grow the array to a sensible size (like half of the current size) as the impact on memory allocation is going to be mitigated by the dynamic allocation approach introduced by MS RFC 24: Mapscript memory management
MS RFC 24: Mapscript memory management did not make a formal requirement to use the proper insert methods as those and the object constructors are the only way to add a layer, class or style to a map. I do not know if this is also true for symbols.
I’m not aware of any MapScript way to bypass the insert or the constructors (i.e. with direct manipulation of the arrays). It there was such way (which I doubt) I suggest that we forbid it by explicitly changing the MS_MAX_* names and making required fields immutable in swig.