slice_init :: fn (_v: Any, n: s64, loc: )

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.


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

    return 0;

Declared in: