1

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

qzcx
  • 361
  • 1
  • 12

1 Answers1

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.

Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
  • so new will leave all fields as NULL? – qzcx Jun 30 '15 at 14:55
  • 1
    'new' initializes default values: - Sets the initial value of the struct to NULL. - Sets the initial value of lists to (empty), unless the list is a sized list of scalars, in which case it is initialized to the proper size with each item set to the default value. - Sets the initial value of all fields of scalar type, including enumerated scalar type, to zero. – Semadar Jul 01 '15 at 05:35