@@ -3478,13 +3478,25 @@ method n() -> (bool, int) {
34783478
34793479<pre >
34803480delete <em >expr</em >;
3481+ delete\<<em >spec</em >\> <em >expr</em >;
34813482</pre >
34823483
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).
34883500
34893501### Try Statements
34903502
@@ -4145,16 +4157,39 @@ independent method callback(int i, void *aux) {
41454157new <em >type</em >
41464158
41474159new <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 >]
41484164</pre >
41494165
41504166Allocates 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
41524168be allocated. The result is a pointer to the allocated memory. (The
41534169pointer is never null; if allocation should fail, the Simics
41544170application will be terminated.)
41554171
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+
41564189When 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.
41584193
41594194### Cast Expressions
41604195
0 commit comments