简体   繁体   中英

Difference between “new” and “gen”

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"?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM