Difference between “new” and “gen”

房东的猫 提交于 2019-12-24 15:42:33

问题


I've done a little playing around in the console and debugger, but I've still got some questions about how new and gen work differently from each other.

What is the difference between using new to generate a struct verse using gen to generate a struct?

Does "gen" use existing allocated memory and "new" allocate new memory? or both allocate memory?

Does "new" generate everything like a "gen" statement?

In cdnshelp it says "new" is a shallow struct, meaning struct fields are not allocated. Is this also true of "gen"?


回答1:


Calling new will allocate memory for the struct (except for other internal struct fields) and call that struct's init() function.

Calling gen will do everything new does, but also randomize the struct's fields. If any of the struct's fields are other structs, it will call gen on them too.



来源:https://stackoverflow.com/questions/31140777/difference-between-new-and-gen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!