blob: bdd3eb3104466ac03f2cb5405fb8f7d1776f3556 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstrad59c3892019-11-28 20:53:39 +01002 mixed * allocate(int size)
3 mixed * allocate(int size, mixed init_value)
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005 mixed * allocate(int *sizes)
6 mixed * allocate(int *sizes, mixed init_value)
MG Mud User88f12472016-06-24 23:31:02 +02007
Zesstra715ec202025-07-09 22:18:31 +02008DESCRIPTION
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 User88f12472016-06-24 23:31:02 +020012
Zesstra715ec202025-07-09 22:18:31 +020013 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 User88f12472016-06-24 23:31:02 +020016
Zesstra715ec202025-07-09 22:18:31 +020017 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 User88f12472016-06-24 23:31:02 +020020
Zesstra715ec202025-07-09 22:18:31 +020021 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
26EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020027 string *buffer;
28 buffer = allocate(50);
29 buffer = allocate(50, "");
30
31 buffer = allocate( ({ 2, 3 }) )
32 --> ({ ({ 0, 0, 0 }), ({ 0, 0, 0 }) })
33
Zesstra715ec202025-07-09 22:18:31 +020034HISTORY
35 LDMud 3.2.9 added the initialization value and the multi-dimensional
36 allocation.
MG Mud User88f12472016-06-24 23:31:02 +020037
Zesstra715ec202025-07-09 22:18:31 +020038SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020039 sizeof(E)