You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/keywords/stackalloc.md
+50-36Lines changed: 50 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: "stackalloc (C# Reference)"
3
-
ms.date: 07/20/2015
3
+
ms.date: 04/12/2018
4
4
ms.prod: .net
5
5
ms.technology:
6
6
- "devlang-csharp"
@@ -10,45 +10,59 @@ f1_keywords:
10
10
- "stackalloc"
11
11
helpviewer_keywords:
12
12
- "stackalloc keyword [C#]"
13
-
ms.assetid: adc04c28-3ed2-4326-807a-7545df92b852
14
-
caps.latest.revision: 27
15
13
author: "BillWagner"
16
14
ms.author: "wiwagn"
17
15
---
18
16
# stackalloc (C# Reference)
19
-
The `stackalloc` keyword is used in an unsafe code context to allocate a block of memory on the stack.
20
-
21
-
```csharp
22
-
int*block=stackallocint[100];
23
-
```
24
-
25
-
## Remarks
26
-
The keyword is valid only in local variable initializers. The following code causes compiler errors.
27
-
28
-
```csharp
29
-
int*block;
30
-
// The following assignment statement causes compiler errors. You
31
-
// can use stackalloc only when declaring and initializing a local
32
-
// variable.
33
-
block=stackallocint[100];
34
-
```
35
-
36
-
Because pointer types are involved, `stackalloc` requires [unsafe](../../../csharp/language-reference/keywords/unsafe.md) context. For more information, see [Unsafe Code and Pointers](../../../csharp/programming-guide/unsafe-code-pointers/index.md).
37
-
38
-
`stackalloc` is like [_alloca](/cpp/c-runtime-library/reference/alloca) in the C run-time library.
39
-
40
-
The following example calculates and displays the first 20 numbers in the Fibonacci sequence. Each number is the sum of the previous two numbers. In the code, a block of memory of sufficient size to contain 20 elements of type `int` is allocated on the stack, not the heap. The address of the block is stored in the pointer `fib`. This memory is not subject to garbage collection and therefore does not have to be pinned (by using [fixed](../../../csharp/language-reference/keywords/fixed-statement.md)). The lifetime of the memory block is limited to the lifetime of the method that defines it. You cannot free the memory before the method returns.
Unsafe code is less secure than safe alternatives. However, the use of `stackalloc` automatically enables buffer overrun detection features in the common language runtime (CLR). If a buffer overrun is detected, the process is terminated as quickly as possible to minimize the chance that malicious code is executed.
The `stackalloc` keyword is used in an unsafe code context to allocate a block of memory on the stack.
18
+
19
+
```csharp
20
+
int*block=stackallocint[100];
21
+
```
22
+
23
+
## Remarks
24
+
25
+
The keyword is valid only in local variable initializers. The following code causes compiler errors.
26
+
27
+
```csharp
28
+
int*block;
29
+
// The following assignment statement causes compiler errors. You
30
+
// can use stackalloc only when declaring and initializing a local
31
+
// variable.
32
+
block=stackallocint[100];
33
+
```
34
+
35
+
Beginning with C# 7.3, you can use array initializer syntax for `stackalloc` arrays. All the following declarations declare an array with three elements whose values are the integers `1`, `2`, and `3`:
36
+
37
+
```csharp
38
+
// Valid starting with C# 7.3
39
+
int*first=stackallocint[3] { 1, 2, 3 };
40
+
int*second=stackallocint[] { 1, 2, 3 };
41
+
int*third=stackalloc[] { 1, 2, 3 };
42
+
```
43
+
44
+
Because pointer types are involved, `stackalloc` requires an [unsafe](unsafe.md) context. For more information, see [Unsafe Code and Pointers](../../programming-guide/unsafe-code-pointers/index.md)
45
+
46
+
`stackalloc` is like [_alloca](/cpp/c-runtime-library/reference/alloca) in the C run-time library.
47
+
48
+
## Examples
49
+
50
+
The following example calculates and displays the first 20 numbers in the Fibonacci sequence. Each number is the sum of the previous two numbers. In the code, a block of memory of sufficient size to contain 20 elements of type `int` is allocated on the stack, not the heap. The address of the block is stored in the pointer `fib`. This memory is not subject to garbage collection and therefore does not have to be pinned (by using [fixed](fixed-statement.md)). The lifetime of the memory block is limited to the lifetime of the method that defines it. You cannot free the memory before the method returns.
The following example initializes a `stackalloc` array of integers to a bit mask with one bit set in each element. This demonstrates the new initializer syntax available starting in C# 7.3:
Unsafe code is less secure than safe alternatives. However, the use of `stackalloc` automatically enables buffer overrun detection features in the common language runtime (CLR). If a buffer overrun is detected, the process is terminated as quickly as possible to minimize the chance that malicious code is executed.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/keywords/yield.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ foreach (string element in elements)
74
74
On each subsequent iteration of the `foreach` loop, the execution of the iterator body continues from where it left off, again stopping when it reaches a `yield return` statement. The `foreach` loop completes when the end of the iterator method or a `yield break` statement is reached.
75
75
76
76
## Example
77
-
The following example has a `yield return` statement that's inside a `for` loop. Each iteration of the `foreach` statement body in `Process` creates a call to the `Power` iterator function. Each call to the iterator function proceeds to the next execution of the `yield return` statement, which occurs during the next iteration of the `for` loop.
77
+
The following example has a `yield return` statement that's inside a `for` loop. Each iteration of the `foreach` statement body in the `Main` method creates a call to the `Power` iterator function. Each call to the iterator function proceeds to the next execution of the `yield return` statement, which occurs during the next iteration of the `for` loop.
78
78
79
79
The return type of the iterator method is <xref:System.Collections.IEnumerable>, which is an iterator interface type. When the iterator method is called, it returns an enumerable object that contains the powers of a number.
Copy file name to clipboardExpand all lines: docs/framework/deployment/guide-for-administrators.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: ".NET Framework Deployment Guide for Administrators"
3
3
ms.custom: ""
4
-
ms.date: "03/30/2017"
4
+
ms.date: "04/10/2018"
5
5
ms.prod: ".net-framework"
6
6
ms.reviewer: ""
7
7
ms.suite: ""
@@ -160,7 +160,7 @@ This step-by-step article describes how a system administrator can deploy the [!
160
160
161
161
8. Complete the wizard.
162
162
163
-
The packagenow contains all the information you need to silently deploy the .NET Framework 4.5. Before you deploy the package and program, verify that it was installed on the distribution point; see the "Monitor Content" section of [Operations and Maintenance for Content Management in Configuration Manager](http://technet.microsoft.com/library/gg712694.aspx#BKMK_MonitorContent) in the Configuration Manager Documentation Library.
163
+
The package now contains all the information you need to silently deploy the .NET Framework 4.5. Before you deploy the package and program, verify that it was installed on the distribution point; see the "Monitor Content" section of [Operations and Maintenance for Content Management in Configuration Manager](http://technet.microsoft.com/library/gg712694.aspx#BKMK_MonitorContent) in the Configuration Manager Documentation Library.
164
164
165
165
<aname="deploying_package"></a>
166
166
### Deploy the package
@@ -225,12 +225,16 @@ This step-by-step article describes how a system administrator can deploy the [!
225
225
## Troubleshooting
226
226
227
227
### Log file locations
228
-
The following log files are generated during [!INCLUDE[net_v45](../../../includes/net-v45-md.md)] setup:
228
+
The following log files are generated during .NET Framework setup:
229
229
230
-
%temp%\Microsoft .NET Framework 4.5*.txt
231
-
%temp%\Microsoft .NET Framework 4.5*.html
230
+
%temp%\Microsoft .NET Framework *version*\*.txt
231
+
%temp%\Microsoft .NET Framework *version*\*.html
232
232
233
-
You can use the [log collection tool](http://www.microsoft.com/download/details.aspx?id=12493) to collect the [!INCLUDE[net_v45](../../../includes/net-v45-md.md)] log files and to create a compressed cabinet (.cab) file that reduces the size of the files.
233
+
where *version* is the version of the .NET Framework that you're installing, such as 4.5 or 4.7.2.
234
+
235
+
You can also specify the directory to which log files are written by using the `/log` command-line option in the .NET Framework installation command. For more information, see [.NET Framework deployment guide for developers](deployment-guide-for-developers.md#command-line-options).
236
+
237
+
You can use the [log collection tool](https://www.microsoft.com/download/details.aspx?id=12493) to collect the .NET Framework log files and to create a compressed cabinet (.cab) file that reduces the size of the files.
0 commit comments