slice_init :: fn (_v: Any, n: s64)
Allocate heap memory for n elements in _v slice. Allocated block is set to zero default value. Allocated memory must be released by slice_terminate call.
This way of memory allocation cause some overhead compared to plain alloc due to conversion to Any and more ‘generic’ behaviour, also setting to 0 have some runtime cost. Consider use of alloc instead in performance-critical cases.
_v Slice to be initialized.
n Number of elements.
main :: fn () s32 { // Allocate slice of 10 numbers sl: []s32; slice_init(sl, 10); loop i := 0; i < sl.len; i += 1 { sl[i] = i; } // release memory allocated by init slice_terminate(sl); return 0; }
Declared in: memory.bl