Alloate a chuck on the stack : Stackalloc : Unsafe C# Examples


C# Examples » Unsafe » Stackalloc »

 

Alloate a chuck on the stack





You can allocate memory from the stack by using stackalloc.
stackalloc can be used only when initializing local variables.
stackalloc has this general form:




    
type  *p  =  stackalloc  type[size]
    
   
  
   

stackalloc must be used in an unsafe context.




    
using  System;
using  System.Globalization;

public  class  MainClass{

    static  void  Main(string[]  args)
    {
            
        unsafe    
        {
            char*  p  =  stackalloc  char[256];
            for  (int  k  =  0;  k  <  256;  k++)  
                p[k]  =  (char)k;
        }    
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Unsafe
» Stackalloc