-
-
Notifications
You must be signed in to change notification settings - Fork 9
Malloc
IsaacShelton edited this page Nov 13, 2022
·
3 revisions
One way to dynamically allocate memory, is using malloc() (as opposed to new).
malloc(size_in_bytes)
In order to use malloc(), you must import one or more of the following:
-
2.7/cstdlib.adept(recommended) sys/cstdlib.adept2.7/basics.adept
The result value will be a ptr to the newly heap-allocated memory.
Since malloc() operates in terms of bytes, it is often necessary to use sizeof in combination with malloc().
malloc(10 * sizeof int)
The difference between new and malloc(), is that new will zero-initialize the allocated memory by default.
You can optionally use new/delete instead of malloc()/free()
See here for more information