MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 2 | mixed * allocate(int size) |
| 3 | mixed * allocate(int size, mixed init_value) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 5 | mixed * allocate(int *sizes) |
| 6 | mixed * allocate(int *sizes, mixed init_value) |
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 | DESCRIPTION |
| 9 | Allocate an array of size elements. The number of elements |
| 10 | must be >= 0 and not bigger than a system maximum (usually |
| 11 | 1000). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 12 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 13 | If <init_value> is given, all array elements will be set |
| 14 | to this value (if <init_value> is an array or mapping, a shallow |
| 15 | copy will be created for each element), otherwise they all will be 0. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 17 | In the second form (using an array of sizes instead of one size), |
| 18 | the efun will allocate a multidimensional array, that is an array |
| 19 | of arrays. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 20 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 21 | Note that this function is hardly needed anymore, because |
| 22 | arrays can be added by the + operator, and can be constructed |
| 23 | and initialized by the ({ }) operator. The functions only |
| 24 | use is to construct big empty arrays. |
| 25 | |
| 26 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 27 | string *buffer; |
| 28 | buffer = allocate(50); |
| 29 | buffer = allocate(50, ""); |
| 30 | |
| 31 | buffer = allocate( ({ 2, 3 }) ) |
| 32 | --> ({ ({ 0, 0, 0 }), ({ 0, 0, 0 }) }) |
| 33 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 34 | HISTORY |
| 35 | LDMud 3.2.9 added the initialization value and the multi-dimensional |
| 36 | allocation. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 37 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 38 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 39 | sizeof(E) |