allocate_mapping |
Discworld driver help |
allocate_mapping |
Name
allocate_mapping() - pre-allocate space for a mapping
Synopsis
mapping allocate_mapping( int size );
mapping allocate_mapping( mixed *keys, mixed values );
Description
Returns a mapping with space for `size' elements preallocated.
For example:
mapping x;
int y = 200;
x = allocate_mapping(y);
where y is the initial size of the mapping. Using allocate_mapping() is the preferred way to initalize the mapping if you have some idea of how many elements the map will contain (200 in this case). The reason is that allocating storage all at once is slightly more efficient. Thus if you are using mappings to store a soul with 200 entries, the above initialization would be quite appropriate. Note, that the above initialization does not restrict you to 200 entries.
Mappings can also be allocated with all its keys. If `values' is an array, it must have the same number of members as `keys'. A mapping will then be allocated mapping the n:th member of `keys' to the n:th member of `values'. If `values' is a function pointer, it will be evaluated with each of the members of `keys', mapping that member to the value returned from the function pointer. If `values' is not an array or a function pointer, each member of `keys' will be mapped to `values'. In all these cases, if some value occurs more than once in `keys', only the last occurance will make it into the finished mapping.