Skip to content

Commit

Permalink
Update expressions.md
Browse files Browse the repository at this point in the history
Squeeze a definition of Span<T> into the description of stackalloc as it is not defined elsewhere.
  • Loading branch information
Nigel-Ecma authored and jskeet committed Aug 17, 2023
1 parent 877c2ee commit 1d4df0d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions standard/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3118,11 +3118,13 @@ When a *stackalloc_initializer* is present:

Each *stackalloc_element_initializer* shall have an implicit conversion to *unmanaged_type* ([§10.2](conversions.md#102-implicit-conversions)). The *stackalloc_element_initializer*s initialize elements in the allocated memory in increasing order, starting with the element at index zero. In the absence of a *stackalloc_initializer*, the content of the newly allocated memory is undefined.

The result of a *stackalloc_expression* is an instance of type `Span<T>`, where `T` is the *unmanaged_type* and the instance’s `Length` property returns the number of items allocated.
The result of a *stackalloc_expression* is an instance of type `Span<T>`, where `T` is the *unmanaged_type*:

> *Note*: When occurring in unsafe code the result of a *stackalloc_expression* may be of a different type, see ([§23.9](unsafe-code.md#239-stack-allocation)). *end note*
- `Span<T>` ([§C.3](standard-library.md#c3-standard-library-types-not-defined-in-isoiec-23271)) is a ref struct type ([§16.2.3](structs.md#1623-ref-modifier)), which presents a block of memory, here the block allocated by the *stackalloc_expression*, as an indexable collection of typed (`T`) items.
- The result’s `Length` property returns the number of items allocated.
- The result’s indexer ([§15.9](classes.md#159_indexers)) returns a *variable_reference* ([§9.5](variables.md#95-variable-references)) to an item of the allocated block and is range checked.

Access via an instance of `Span<T>` to the elements of an allocated block is range checked.
> *Note*: When occurring in unsafe code the result of a *stackalloc_expression* may be of a different type, see ([§23.9](unsafe-code.md#239-stack-allocation)). *end note*
Stack allocation initializers are not permitted in `catch` or `finally` blocks ([§13.11](statements.md#1311-the-try-statement)).

Expand Down

0 comments on commit 1d4df0d

Please sign in to comment.