blob: 7c755307ed4bed43f48177859b154a9929f52239 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
2 mapping m_allocate(int size)
3 mapping m_allocate(int size, int width)
4
Zesstra715ec202025-07-09 22:18:31 +02005DESCRIPTION
6 Reserve memory for a mapping.
MG Mud User88f12472016-06-24 23:31:02 +02007
Zesstra715ec202025-07-09 22:18:31 +02008 <size> is the number of entries (i.e. keys) to reserve, <width> is
9 the number of data items per entry. If the optional width is
10 omitted, 1 is used as default.
MG Mud User88f12472016-06-24 23:31:02 +020011
Zesstra715ec202025-07-09 22:18:31 +020012 This is useful only when you are going to construct a mapping
13 whose approximate size you know beforehand, to save overhead on
14 repeated memory allocations. If you don't fill in data for all the
15 allocated elements, any leftovers will be eventually freed some time
16 later (see remark below).
17 It is also useful if you want the mapping to have a certain width
18 even if you don't provide all the data items for the keys yet.
MG Mud User88f12472016-06-24 23:31:02 +020019
Zesstra715ec202025-07-09 22:18:31 +020020 If the goal is just to create an empty mapping with a certain
21 width, the following notations can be used:
MG Mud User88f12472016-06-24 23:31:02 +020022
Zesstra715ec202025-07-09 22:18:31 +020023 ([ ]) : creates an empty mapping of width 1.
MG Mud User88f12472016-06-24 23:31:02 +020024
Zesstra715ec202025-07-09 22:18:31 +020025 ([:width ]) : creates an empty mapping the given <width>, where
26 <width> can be any expression yielding an integer result. In
27 fact this notation is compiled as 'm_allocate(0, width)' .
MG Mud User88f12472016-06-24 23:31:02 +020028
Zesstra715ec202025-07-09 22:18:31 +020029EXAMPLES
30 m_allocate(3, 7) -> mapping with 7 values per key, and with space
31 for 3 entries.
MG Mud User88f12472016-06-24 23:31:02 +020032
Zesstra715ec202025-07-09 22:18:31 +020033 ([:2*3 ]) -> same as m_allocate(0, 6)
34
35REMARKS
36 Unused memory in the allocated mapping will be freed during the
37 so-called compacting of the mapping. This is done during the
38 data-cleanup or the garbage collection. The time between
39 data-cleanups is configurable by configure_driver().
40
41HISTORY
42 Renamed from 'allocate_mapping' in LDMud 3.2.6.
43 The ([:width ]) notation was introduced in LDMud 3.2.9 / 3.3.208.
44
45SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020046 mappings(LPC), walk_mapping(E), get_type_info(E), m_reallocate(E)