使用指针优化性能
============================创建基于栈的数组(高性能,低系统开销)
平城网站建设公司创新互联公司,平城网站设计制作,有大型网站制作公司丰富经验。已为平城1000多家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的平城做网站的公司定做!
//数组的类型必须为值类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static unsafe void Main(string[] args)
{
//stackalloc返回的地址的指针
//分配的字节数=项数*sizeof(类型)
int size = 20;//项数为20
int* iarr = stackalloc int[size];
for (int i = 0; i < size; i++)
{
//iarr[i] = i; //这种模式也可以
*(iarr + i) = i;
}
for (int j = 0; j < size; j++)
{
//Console.WriteLine(iarr[j]); //这种模式也可以
Console.WriteLine(*(iarr + j));
}
Console.ReadKey();
}
}
}//如果给20个int数分配存储单元,就得到了一个有20个元素的int数组,最简单的数组类型是逐个存储元素的内存块

网页名称:使用指针优化性能
当前链接:http://www.jxjierui.cn/article/jepsgh.html


咨询
建站咨询
