当前位置: 首页 > news >正文

百度手机网站优化指南网站群的建设目标

百度手机网站优化指南,网站群的建设目标,vs2010做网站,程序员学历要求高吗1. 先看一个例子 package mainimport fmtfunc main() {var a *int*a 10fmt.Println(*a) }运行结果是啥呢#xff1f; 问#xff1a;为什么会报这个panic呢#xff1f; 答#xff1a;因为如果是一个引用类型#xff0c;我们不仅要声明它#xff0c;还要为… 1. 先看一个例子 package mainimport fmtfunc main() {var a *int*a 10fmt.Println(*a) }运行结果是啥呢 问为什么会报这个panic呢 答因为如果是一个引用类型我们不仅要声明它还要为它分配内存空间否则我们赋值的 10 就无处安放。值类型的声明不需要我们分配内存空间因为已经默认给我们分配好啦。 问那么如何分配内存呢 答在使用a这个引用类型的变量之前给它分配内存内存即可。 package mainimport fmtfunc main() {var a *inta new(int)*a 10fmt.Println(*a) }问听说对变量分配内存有new和make函数两种我应该在对各种变量初始化和分配内存时用哪个呢 答在golang中的源码中已经做出了解释可以接着看后面的内容。 2. 源码中的描述 make函数用来对slice、map、和channel类型的初始化和分配内存。和new函数一样第一个参数是一个类型而不是值和new函数不一样的是make函数的返回类型和传入参数的类型一致而new函数的返回类型是传入类型的指针。特定的结果依赖于传入的类型 slicesize指定切片的长度容量在不指定的情况下和长度相等。如果额外指定容量则容量可能和长度不相等。比如make([]int,0,10)分配了一个大小为10的底层数组并返回一个长度为0、容量为10的切片该切片由这个底层数组支持。map一个空的map被分配了足够的空间以容纳指定数量的元素。如果省略了大小则会分配一个较小的起始大小。通道的缓冲区使用指定的缓冲区容量进行初始化。如果容量为0或者未指定大小则通道是无缓冲的。 new函数用于分配内存。其第一个参数是一个类型而不是一个值返回的值是指向新分配的内存的指针该内存的内容是该类型的零值。 // The make built-in function allocates and initializes an object of type // slice, map, or chan (only). Like new, the first argument is a type, not a // value. Unlike new, makes return type is the same as the type of its // argument, not a pointer to it. The specification of the result depends on // the type: // // Slice: The size specifies the length. The capacity of the slice is // equal to its length. A second integer argument may be provided to // specify a different capacity; it must be no smaller than the // length. For example, make([]int, 0, 10) allocates an underlying array // of size 10 and returns a slice of length 0 and capacity 10 that is // backed by this underlying array. // Map: An empty map is allocated with enough space to hold the // specified number of elements. The size may be omitted, in which case // a small starting size is allocated. // Channel: The channels buffer is initialized with the specified // buffer capacity. If zero, or the size is omitted, the channel is // unbuffered. func make(t Type, size ...IntegerType) Type// The new built-in function allocates memory. The first argument is a type, // not a value, and the value returned is a pointer to a newly // allocated zero value of that type. func new(Type) *Type 3. 两者的异同 相同点 new 和 make 都是用于内存的分配。new 用于给类型分配内存空间并且变量的值为零。 不同点 make 只用于 chanmapslice 的初始化。make 返回类型本身new 返回指向类型的指针。
http://www.zqtcl.cn/news/854623/

相关文章:

  • 徐州整站优化手机网页端
  • 深圳中瑞建设集团官方网站宁波seo快速优化教程
  • 福田网站制作哪家好昆山企业网站建设公司
  • wordpress快六安网站自然排名优化价格
  • 网站的线下推广怎么做的系统官网网站模板下载安装
  • 北京网站优化推广公司企业网站建设费怎么核算
  • 网站建设vps个人如何做网站推广
  • 小语种网站怎么设计网页制作公司 大连
  • 贵港市城乡住房建设厅网站菜鸟教程网站
  • 广州网站建设找哪家免费搭建网站的软件
  • 培训班管理系统 免费太原优化网站排名
  • 上海怎么做网站网站让图片充满屏幕怎么做
  • 哈尔滨营销网站建设wordpress 加载图片不显示
  • 电商网站功能结构图网站做中秋专题怎么弄
  • 深圳专业建站平台陕西省建设工程质量安全监督总站网站
  • 制作网页的网站的软件是用户反馈数据分析软件园
  • 南京 做网站seo查询网站
  • 卖高仿名牌手表网站共享wifi小程序搭建
  • c#网站开发模板想在意大利做购物网站
  • 2015做那些网站能致富60天做网站
  • 沈阳个人建站模板网站图片计时器怎么做
  • 福州定制网站开发北京排名seo
  • 地方门户网站开发方案长沙有哪个学校可以学网站建设
  • 建个购物网站水果建设网站前的市场分析
  • 建网站的目的小程序登录代码
  • 南京有名的网站建设公司自学室内装修设计教程
  • 新乡市做网站的公司开发公司简介企业介绍
  • 礼品网站模板淘宝店铺购买交易平台
  • 属于公司的网站怎么做外贸服装网站开发
  • 做暧网站泸州公司做网站