IT. Expert System.

C#

stackalloc


The stackalloc keyword is used in an unsafe code context to allocate a block of memory on the stack .The keyword is valid only in local variable initializers. The following code causes compiler errors. stackalloc is like _alloca in the C run-time library.

Syntax:
dataType* variable = stackalloc dataType[size];


Example:

using System;

class Program
{
    unsafe static string GetStringStackalloc()
    {
	// Allocate a character buffer with the stackalloc operator.
	// ... Assign the memory to specific letters.
	// ... Add the terminal character.
	char* buffer = stackalloc char[50 + 1];
	for (int i = 0; i < 10; i++)
	{
	    buffer[i] = 'a';
	}
	for (int i = 10; i < 50; i++)
	{
	    buffer[i] = 'z';
	}
	buffer[50] = '\0';
	return new string(buffer);
    }

    static void main()
    {
	// call the stackalloc method to get the result string.
	// ... also demonstrate its correctness by using the string constructor.
	console.writeline(getstringstackalloc());
	console.writeline(new string('a', 10) + new string('z', 40));
    }
}

/*output

aaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
aaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz*/


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 94 / 96397575. Delta: 0.00908 с