Главная -> Голые Девочки
The stackalloc keyword is used in an unsafe code context to allocate a block of истории сексизмен on the stack. The keyword is valid only in local variable initializers.
The following code causes compiler errors. Beginning with C 7. All the following declarations declare an array with three elements whose values are the integers 1 истории сексизмен, 2and Because pointer types are involved, stackalloc requires an unsafe context.
Истории сексизмен more information, see Unsafe Code and Pointers.
The following example calculates and displays the first 20 numbers in the Fibonacci sequence. Each number is the sum of истории сексизмен previous two numbers.
In the code, a block of memory of sufficient size to contain 20 elements истории сексизмен type int is allocated on the stack, not the heap.
The address of the block истории сексизмен stored in the pointer fib. This memory is not subject to garbage collection and therefore does not have to be pinned by using fixed.
Истории сексизмен 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 истории сексизмен 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.
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.
For more истории сексизмен, see the C Language Specification. The language specification is истории сексизмен definitive source for C syntax and usage.
Our new feedback system is built on GitHub Issues. Read about this change in our blog post. All the following declarations declare an array with three elements whose values истории сексизмен the integers 12and 3: Examples The following example calculates and displays the first 20 numbers истории сексизмен the Fibonacci sequence.
Product feedback Sign in to give documentation feedback Content feedback You may also leave feedback directly on GitHub. There are истории сексизмен open issues.