# allocate_struct

Definition: | include cffi.e atom pStruct = allocate_struct(integer idStruct, bool cleanup=true)
Description: | allocate memory for a structure previously defined using define_struct().
pwa/p2js: | Not supported.
Comments: | The allocated memory is automatically zero-filled. Note that, unlike the allocate() function which it invokes internally, where it must be false otherwise it would break almost all legacy code, the cleanup argument default is true. Should you override it to false, remember to free() the result once no longer needed. Note that when cleanup is true, ie the default automatic memory management is in force, you should avoid invoking free() or delete() on pStruct explicitly: doing so is guaranteed to leave an invalid pointer to memory lying around. In preference you should either let things happen naturally, or explicitly set the last/only copy of pStruct to NULL, and in that way ensure the raw memory is not actually freed until it is guaranteed safe to do so, and accidental references to it will not cause unpredictable memory corruption.
Example: |
    include cffi.e
    integer idMBP = define_struct(...)
    atom pMBP = allocate_struct(idMBP)
    ...
    free(pMBP)
See Also: | define_struct, free