Search code examples
specmane

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


Solution

  • 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.