Reputation: 27689
How to delete all zero values or unassigned values?
Here a stack trace is put into a slice.. How can all the unassigned (zero values) be deleted?
Is there some fancy function to slice a slice.. Something like substring of a string
trace := make([]byte, 1024)
runtime.Stack(trace, true)
Upvotes: 0
Views: 775
Reputation: 6425
Use a slice expression to trim the unused portion of the stack buffer. The Stack function conveniently returns the number of bytes written to the buffer.
trace := make([]byte, 1024)
n := runtime.Stack(trace, true)
trace = trace[:n]
Upvotes: 1