golang/go
View on GitHubsizeof: new package with constants for Int, Uint, Uintptr, Int8, Float64, etc
Open
#29,982 opened on Jan 29, 2019
ProposalProposal-AcceptedProposal-Holdhelp wanted
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
See the tail of the (closed) proposal #5602. There I suggested that instead of making unsafe.Sizeof a safe thing, which it still kinda isn't in general, we solve 90% of the problem by add easy-to-use constants to a safe package, such as:
package reflect
const (
SizeofInt = <size on this machine>
SizeofUint = SizeofInt
SizeofBool = 1
SizeofFloat64 = 8
//...
)
These would be defined for primitive types only, not slices, maps, etc. You'd still need the unsafe package to handle them.