golang/go

sizeof: new package with constants for Int, Uint, Uintptr, Int8, Float64, etc

Open

#29,982 opened on Jan 29, 2019

View on GitHub
 (42 comments) (41 reactions) (0 assignees)Go (19,008 forks)batch import
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.

Contributor guide