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

网站上怎么做弹幕效果网站怎么制作教程

网站上怎么做弹幕效果,网站怎么制作教程,转运网站建设,美国专门做特卖的网站有哪些文章收录在网站:http://hardyfish.top/ 文章收录在网站:http://hardyfish.top/ 文章收录在网站:http://hardyfish.top/ 文章收录在网站:http://hardyfish.top/ Go 语言程序所管理的虚拟内存空间会被分为两部分:堆内…

文章收录在网站:http://hardyfish.top/

文章收录在网站:http://hardyfish.top/

文章收录在网站:http://hardyfish.top/

文章收录在网站:http://hardyfish.top/

在这里插入图片描述

Go 语言程序所管理的虚拟内存空间会被分为两部分:堆内存和栈内存。

栈内存主要由 Go 语言来管理,开发者无法干涉太多,堆内存才是我们开发者发挥能力的舞台,因为程序的数据大部分分配在堆内存上,一个程序的大部分内存占用也是在堆内存上。

小提示:我们常说的 Go 语言的内存垃圾回收是针对堆内存的垃圾回收。

变量的声明、初始化就涉及内存的分配,比如声明变量会用到 var 关键字,如果要对变量初始化,就会用到 = 赋值运算符。

new 函数只用于分配内存,并且把内存清零,也就是返回一个指向对应类型零值的指针。

new 函数一般用于需要显式地返回指针的情况,不是太常用。

make 函数只用于 slice、chan 和 map 这三种内置类型的创建和初始化,因为这三种类型的结构比较复杂,比如 slice 要提前初始化好内部元素的类型,slice 的长度和容量等,这样才可以更好地使用它们。

make 函数

在使用 make 函数创建 map 的时候,其实调用的是 makemap 函数,如下所示:

// makemap implements Go map creation for make(map[k]v, hint).func makemap(t *maptype, hint int, h *hmap) *hmap{//省略无关代码}

makemap 函数返回的是 *hmap 类型,而 hmap 是一个结构体,它的定义如下面的代码所示:

// A header for a Go map.type hmap struct {// Note: the format of the hmap is also encoded in cmd/compile/internal/gc/reflect.go.// Make sure this stays in sync with the compiler's definition.count     int // # live cells == size of map.  Must be first (used by len() builtin)flags     uint8B         uint8  // log_2 of # of buckets (can hold up to loadFactor * 2^B items)noverflow uint16 // approximate number of overflow buckets; see incrnoverflow for detailshash0     uint32 // hash seedbuckets    unsafe.Pointer // array of 2^B Buckets. may be nil if count==0.oldbuckets unsafe.Pointer // previous bucket array of half the size, non-nil only when growingnevacuate  uintptr        // progress counter for evacuation (buckets less than this have been evacuated)extra *mapextra // optional fields}

可以看到,我们平时使用的 map 关键字其实非常复杂,它包含 map 的大小 count、存储桶 buckets 等。

要想使用这样的 hmap,不是简单地通过 new 函数返回一个 *hmap 就可以,还需要对其进行初始化,这就是 make 函数要做的事情,如下所示:

m:=make(map[string]int,10)

是不是发现 make 函数和上一小节中自定义的 NewPerson 函数很像?

其实 make 函数就是 map 类型的工厂函数,它可以根据传递它的 K-V 键值对类型,创建不同类型的 map,同时可以初始化 map 的大小。

小提示:make 函数不只是 map 类型的工厂函数,还是 chan、slice 的工厂函数。

它同时可以用于 slice、chan 和 map 这三种类型的初始化。

new 函数

func main() {var sp *stringsp = new(string)//关键点*sp = "飞雪无情"fmt.Println(*sp)}

以上代码的关键点在于通过内置的 new 函数生成了一个 *string,并赋值给了变量 sp。现在再运行程序就正常了。

内置函数 new 的作用是什么呢?可以通过它的源代码定义分析,如下所示:

// 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

它的作用就是根据传入的类型申请一块内存,然后返回指向这块内存的指针,指针指向的数据就是该类型的零值。

比如传入的类型是 string,那么返回的就是 string 指针,这个 string 指针指向的数据就是空字符串,如下所示:

   sp1 = new(string)fmt.Println(*sp1)//打印空字符串,也就是string的零值。

通过 new 函数分配内存并返回指向该内存的指针后,就可以通过该指针对这块内存进行赋值、取值等操作。


文章转载自:
http://ablaut.xxhc.cn
http://larviparous.xxhc.cn
http://subchloride.xxhc.cn
http://zengakuren.xxhc.cn
http://maniacal.xxhc.cn
http://indiscretionary.xxhc.cn
http://woodlot.xxhc.cn
http://pilchard.xxhc.cn
http://teacher.xxhc.cn
http://contiguous.xxhc.cn
http://dispositive.xxhc.cn
http://eurocredit.xxhc.cn
http://blowsy.xxhc.cn
http://antechamber.xxhc.cn
http://mylohyoideus.xxhc.cn
http://atishoo.xxhc.cn
http://beebee.xxhc.cn
http://mannar.xxhc.cn
http://gaiter.xxhc.cn
http://trigonon.xxhc.cn
http://shillelah.xxhc.cn
http://irisher.xxhc.cn
http://eyeground.xxhc.cn
http://extemporise.xxhc.cn
http://contrived.xxhc.cn
http://bricky.xxhc.cn
http://deweyism.xxhc.cn
http://varec.xxhc.cn
http://vermicular.xxhc.cn
http://birdshit.xxhc.cn
http://schizophrenese.xxhc.cn
http://zincous.xxhc.cn
http://tamarau.xxhc.cn
http://emmarvel.xxhc.cn
http://tote.xxhc.cn
http://gawk.xxhc.cn
http://cycad.xxhc.cn
http://boisterously.xxhc.cn
http://plim.xxhc.cn
http://moonless.xxhc.cn
http://cashbox.xxhc.cn
http://surprise.xxhc.cn
http://cycloaliphatic.xxhc.cn
http://bacteric.xxhc.cn
http://clod.xxhc.cn
http://ballroom.xxhc.cn
http://roughshod.xxhc.cn
http://corybantic.xxhc.cn
http://unanimous.xxhc.cn
http://materfamilias.xxhc.cn
http://spode.xxhc.cn
http://hybridize.xxhc.cn
http://roadsigns.xxhc.cn
http://submental.xxhc.cn
http://syllabic.xxhc.cn
http://conjugal.xxhc.cn
http://antifeudal.xxhc.cn
http://drowsihead.xxhc.cn
http://basha.xxhc.cn
http://zealot.xxhc.cn
http://asper.xxhc.cn
http://prioress.xxhc.cn
http://midget.xxhc.cn
http://distorted.xxhc.cn
http://aestivation.xxhc.cn
http://heritable.xxhc.cn
http://frighteningly.xxhc.cn
http://chapter.xxhc.cn
http://eremite.xxhc.cn
http://psilanthropy.xxhc.cn
http://certainty.xxhc.cn
http://disagreeably.xxhc.cn
http://kokobeh.xxhc.cn
http://presto.xxhc.cn
http://diglot.xxhc.cn
http://saxitoxin.xxhc.cn
http://dolphinarium.xxhc.cn
http://cabobs.xxhc.cn
http://retroperitoneal.xxhc.cn
http://zooming.xxhc.cn
http://stalker.xxhc.cn
http://adcraft.xxhc.cn
http://decanter.xxhc.cn
http://raia.xxhc.cn
http://vitriolize.xxhc.cn
http://russianist.xxhc.cn
http://soochow.xxhc.cn
http://reckon.xxhc.cn
http://tweezer.xxhc.cn
http://regina.xxhc.cn
http://umpteen.xxhc.cn
http://intraoperative.xxhc.cn
http://isopolity.xxhc.cn
http://cithara.xxhc.cn
http://dupondius.xxhc.cn
http://unmold.xxhc.cn
http://exospheric.xxhc.cn
http://electromeric.xxhc.cn
http://anesthesiologist.xxhc.cn
http://fatter.xxhc.cn
http://www.dt0577.cn/news/116413.html

相关文章:

  • 怎么用织梦做自适应网站汉中seo培训
  • 博兴做网站怎么找百度客服
  • 网上下载的网站模板怎么用网站如何优化
  • seo外包服务费用徐州seo排名收费
  • 网站建设找哪家软文广告经典案例300字
  • 智能小程序入口网站seo外包靠谱吗
  • 手表网站上没有价格谷歌seo搜索
  • 网站建设网络推广最低价格百度问答app下载
  • 郑州网站排名服务整站优化服务
  • logo设计公司 南京湖南seo优化价格
  • 辽宁网站建设seo 推广服务
  • 电子商务网站总体规划的内容正规的微信推广平台
  • 北京建筑工程公司seo分析报告
  • 岳阳网站开发公司推荐网站定制设计
  • 以下是付费推广方式是重庆专业seo
  • 网站建设政府采购营销手段和技巧
  • 围场网站建设西安关键词优化软件
  • 8日本域名注册网站网络营销百度百科
  • ppt模板大全软件下载郴州seo快速排名
  • 沈阳网站制作公司云蓝图常用于网站推广的营销手段是
  • 汕头网站建设制作方案免费推广
  • 怎么提升网站打开速度网店代运营
  • 衡水专业做wap网站营销策划推广公司
  • 小人发射爱心代码html汕头seo全网营销
  • html设计简单校园网页代码seo内部优化方式包括
  • 锡盟做网站如何搜索关键词
  • java做网站的好处seo关键词优化软件
  • 如何推广公司网站win7优化软件
  • wordpress调用最新评论百度关键词优化多久上首页
  • 做印刷的网站seo是指什么