Go Slices: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 4: Line 4:


=Overview=
=Overview=
A slice is a descriptor for a contiguous segment of an underlying [[Go_Arrays#Overview|array]]. A slice type denotes the set of all slices of arrays of its element types. Slice was used to be referred to as a [[Go_Language#Reference_Type|reference type]], but not anymore, as reference type terminology was removed from Go documentation.
A slice is a descriptor for a contiguous segment of an underlying [[Go_Arrays#Overview|array]]. A slice type denotes the set of all slices of arrays of its element types. The slice was used to be referred to as a [[Go_Language#Reference_Type|reference type]], but not anymore, as reference type terminology was removed from Go documentation.


A slice contains a pointer to the underlying array, a length and a capacity. More details available in the [[#Structure|structure]] section.
A slice contains a pointer to the underlying array, a length and a capacity. More details available in the [[#Structure|structure]] section.

Revision as of 17:05, 15 August 2024

External

Internal

Overview

A slice is a descriptor for a contiguous segment of an underlying array. A slice type denotes the set of all slices of arrays of its element types. The slice was used to be referred to as a reference type, but not anymore, as reference type terminology was removed from Go documentation.

A slice contains a pointer to the underlying array, a length and a capacity. More details available in the structure section.

Go uses pass-by-value, so when slice arguments are passed to functions, the internal fields are copied across, including the pointer to the underlying array. Therefore, the underlying data structure is intrinsically shared even in presence of pass-by-value.

Structure

TODEPLETE

Go Slices TODPLETE