MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
| 2 | mapping m_allocate(int size) |
| 3 | mapping m_allocate(int size, int width) |
| 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 5 | DESCRIPTION |
| 6 | Reserve memory for a mapping. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 7 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 8 | <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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 11 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 12 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 19 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 20 | If the goal is just to create an empty mapping with a certain |
| 21 | width, the following notations can be used: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 22 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 23 | ([ ]) : creates an empty mapping of width 1. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 24 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 25 | ([: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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 28 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 29 | EXAMPLES |
| 30 | m_allocate(3, 7) -> mapping with 7 values per key, and with space |
| 31 | for 3 entries. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 32 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 33 | ([:2*3 ]) -> same as m_allocate(0, 6) |
| 34 | |
| 35 | REMARKS |
| 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 | |
| 41 | HISTORY |
| 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 | |
| 45 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 46 | mappings(LPC), walk_mapping(E), get_type_info(E), m_reallocate(E) |