68
68
$(LI $(GLINK SharedStaticDestructor)s)
69
69
$(LI $(RELATIVE_LINK2 invariants, Class Invariants))
70
70
$(LI $(DDSUBLINK spec/unittest, unittest, Unit Tests))
71
- $(LI $(RELATIVE_LINK2 allocators, Class Allocators))
72
71
$(LI $(RELATIVE_LINK2 alias-this, Alias This))
73
72
)
74
73
)
@@ -1006,74 +1005,6 @@ $(GNAME Invariant):
1006
1005
)
1007
1006
1008
1007
1009
- $(H2 $(LNAME2 allocators, Class Allocators))
1010
- $(B Note): Class allocators are deprecated in D2.
1011
- $(GRAMMAR
1012
- $(GNAME Allocator):
1013
- $(D new) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionBody)
1014
- )
1015
-
1016
- $(P A class member function of the form:)
1017
-
1018
- ------
1019
- new(size_t size)
1020
- {
1021
- ...
1022
- }
1023
- ------
1024
-
1025
- is called a class allocator.
1026
- The class allocator can have any number of parameters, provided
1027
- the first one is of type `size_t`.
1028
- Any number can be defined for a class, the correct one is
1029
- determined by the usual function overloading rules.
1030
- When a new expression:
1031
-
1032
- ------
1033
- new Foo;
1034
- ------
1035
-
1036
- is executed, and Foo is a class that has
1037
- an allocator, the allocator is called with the first argument
1038
- set to the size in bytes of the memory to be allocated for the
1039
- instance.
1040
- The allocator must allocate the memory and return it as a
1041
- $(D void*).
1042
- If the allocator fails, it must not return a $(D null), but
1043
- must throw an exception.
1044
- If there is more than one parameter to the allocator, the
1045
- additional arguments are specified within parentheses after
1046
- the $(D new) in the $(I NewExpression):
1047
-
1048
- ------
1049
- class Foo
1050
- {
1051
- this(string a) { ... }
1052
-
1053
- new(size_t size, int x, int y)
1054
- {
1055
- ...
1056
- }
1057
- }
1058
-
1059
- ...
1060
-
1061
- new(1,2) Foo(a); // calls new(Foo.sizeof,1,2)
1062
- ------
1063
-
1064
- $(P Derived classes inherit any allocator from their base class,
1065
- if one is not specified.
1066
- )
1067
-
1068
- $(P The class allocator is not called if the instance is created
1069
- on the stack.
1070
- )
1071
-
1072
- $(P See also
1073
- $(LINK2 https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation,
1074
- Explicit Class Instance Allocation).
1075
- )
1076
-
1077
1008
$(H2 $(LEGACY_LNAME2 AliasThis, alias-this, Alias This))
1078
1009
1079
1010
$(GRAMMAR
@@ -1479,7 +1410,7 @@ $(H3 $(LNAME2 anonymous, Anonymous Nested Classes))
1479
1410
1480
1411
$(GRAMMAR
1481
1412
$(GNAME NewAnonClassExpression):
1482
- $(D new) $(GLINK2 expression, AllocatorArguments)$(OPT) $( D class) $(GLINK ConstructorArgs)$(OPT) $(GLINK SuperClassOrInterface)$(OPT) $(GLINK Interfaces)$(OPT) $(GLINK2 struct, AggregateBody)
1413
+ $(D new) $(D class) $(GLINK ConstructorArgs)$(OPT) $(GLINK SuperClassOrInterface)$(OPT) $(GLINK Interfaces)$(OPT) $(GLINK2 struct, AggregateBody)
1483
1414
1484
1415
$(GNAME ConstructorArgs):
1485
1416
$(D $(LPAREN)) $(GLINK2 expression, ArgumentList)$(OPT) $(D $(RPAREN))
@@ -1490,7 +1421,7 @@ which is equivalent to:
1490
1421
$(GRAMMAR_INFORMATIVE
1491
1422
$(D class) $(GLINK_LEX Identifier) $(D :) $(I SuperClassOrInterface) $(I Interfaces) $(I AggregateBody)
1492
1423
// ...
1493
- $(D new) $(I AllocatorArguments) $(I Identifier) $(I ConstructorArgs)
1424
+ $(D new) $(I Identifier) $(I ConstructorArgs)
1494
1425
)
1495
1426
1496
1427
where $(I Identifier) is the name generated for the anonymous nested class.
0 commit comments