@@ -3478,13 +3478,25 @@ method n() -> (bool, int) {
3478
3478
3479
3479
<pre >
3480
3480
delete <em >expr</em >;
3481
+ delete\<<em >spec</em >\> <em >expr</em >;
3481
3482
</pre >
3482
3483
3483
- Deallocates the memory pointed to by the result of evaluating
3484
- * ` expr ` * . The memory must have been allocated with the
3485
- ` new ` operator, and must not have been deallocated previously.
3486
- Equivalent to ` delete ` in C++; however, in DML, ` delete `
3487
- can only be used as a statement, not as an expression.
3484
+ Deallocates the memory pointed to by the result of evaluating * ` expr ` * .
3485
+
3486
+ * spec* specifies an * allocation format* , and can either be ` enriched ` or
3487
+ ` extern ` . If not explicitly specified, * spec* will default to ` extern ` . This is
3488
+ for backwards compatibility reasons &mdash ; in the future the default will be
3489
+ changed to be ` enriched ` .
3490
+
3491
+ The * enriched* format uses an allocation format specific to the device model,
3492
+ and so can * only* be used in order to deallocate storage previously allocated
3493
+ via [ ` new<enriched> ` ] ( #new-expressions ) by the same device model.
3494
+
3495
+ The * extern* format compiles the ` delete ` statement to a use of ` MM_FREE ` ,
3496
+ meaning it may be used to deallocate storage previously allocated by any use of
3497
+ Simics's memory allocation functions/macros (such as ` MM_MALLOC ` .) This includes
3498
+ storage allocated via [ ` new<extern> ` ] ( #new-expressions ) (which ` new ` without
3499
+ allocation format specifier is equivalent to).
3488
3500
3489
3501
### Try Statements
3490
3502
@@ -4145,16 +4157,39 @@ independent method callback(int i, void *aux) {
4145
4157
new <em >type</em >
4146
4158
4147
4159
new <em >type</em >[<em >count</em >]
4160
+
4161
+ new\<<em >spec</em >\> <em >type</em >
4162
+
4163
+ new\<<em >spec</em >\> <em >type</em >[<em >count</em >]
4148
4164
</pre >
4149
4165
4150
4166
Allocates a chunk of memory large enough for a value of the specified
4151
- type. If the second form is used, memory for * count* values will
4167
+ type. If a form specifying * count * is used, then memory for * count* values will
4152
4168
be allocated. The result is a pointer to the allocated memory. (The
4153
4169
pointer is never null; if allocation should fail, the Simics
4154
4170
application will be terminated.)
4155
4171
4172
+ * spec* specifies an * allocation format* , and can either be ` enriched ` or
4173
+ ` extern ` . If not explicitly specified, * spec* will default to ` extern ` . This is
4174
+ for backwards compatibility reasons &mdash ; in the future the default will be
4175
+ changed to be ` enriched ` .
4176
+
4177
+ The * enriched* format uses an allocation format specific to the device model,
4178
+ and * must* be used in order to allocate storage for values of [ resource-enriched
4179
+ (RAII) type] ( #raii-types ) . The fact the allocation format is model-specific
4180
+ comes with the drawback that a pointer created with ` new<enriched> ` * cannot be
4181
+ freed* using ` MM_FREE ` /` free ` : only code from the same device model can free it,
4182
+ and only by using [ ` delete<enriched> ` ] ( #delete-statements ) .
4183
+
4184
+ The * extern* format compiles ` new ` to a use of ` MM_ZALLOC ` , meaning a pointer
4185
+ allocated this way may be freed using ` MM_FREE ` outside of the device model.
4186
+ However, this format does not support allocating storage for values of
4187
+ resource-enriched type.
4188
+
4156
4189
When the memory is no longer needed, it should be deallocated using a
4157
- ` delete ` statement.
4190
+ [ ` delete ` statement] ( #delete-statements ) . The allocation format specified for the
4191
+ ` delete ` statement * must* match that of the ` new ` expression used to allocate
4192
+ the pointer.
4158
4193
4159
4194
### Cast Expressions
4160
4195
0 commit comments