Find capacity of Channel, Pointer and Slice
The builtin Cap function is used to find the capacity of Channel, Pointer and Slice. There is no package need to import to use Cap function.
Example
package main
import "fmt"
func main() {
sliceEx := make([]string, 0, 10)
fmt.Printf("\nSlice: %d", cap(sliceEx))
channelEx := make(chan string, 5)
fmt.Printf("\nChannel: %d", cap(channelEx))
var pointerEx *[20]string
fmt.Printf("\nPointer: %d", cap(pointerEx))
}
Output
Slice: 10
Channel: 5
Pointer: 20
Most Helpful This Week
Replace any non-alphanumeric character sequences with a dash using Regex
Example: How to use ReadAtLeast from IO Package in Golang?
Sierpinski triangle in Go Programming Language
How to count number of repeating words in a given String?
How to add and update elements in Map?
Golang Slice vs Map Benchmark Testing
Print index and element or data from Array, Slice and Map
How to Convert string to float type in Go?
How to fix race condition using Atomic Functions in Golang?
Add N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time