问题
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