close
Skip to content

arp242/structalign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

structalign prints the memory alignment of structs.

This is a fork of the structlayout, with some nicer output and more options.

For example:

% structalign net/mail.Address
struct Address, 32 bytes, 0 padding
    Name     string    0-16  (size 16,  align  8)
    Address  string   16-32  (size 16,  align  8)

Or to list everything in a package:

% structalign net/mail/...
struct Address, 32 bytes, 0 padding
    Name     string    0-16  (size 16,  align  8)
    Address  string   16-32  (size 16,  align  8)

struct AddressParser, 8 bytes, 0 padding
    WordDecoder  *mime.WordDecoder    0-8  (size  8,  align  8)

struct Message, 24 bytes, 0 padding
    Header  net/mail.Header    0-8   (size  8,  align  8)
    Body    io.Reader          8-24  (size 16,  align  8)

struct addrParser, 24 bytes, 0 padding
    s    string               0-16  (size 16,  align  8)
    dec  *mime.WordDecoder   16-24  (size  8,  align  8)

struct dateLayoutsBuildOnce, 12 bytes, 0 padding
    _           sync.noCopy           0-0   (size  0,  align  1)
    done._      sync/atomic.noCopy    0-0   (size  0,  align  1)
    done.v      uint32                0-4   (size  4,  align  4)
    m._         sync.noCopy           4-4   (size  0,  align  1)
    m.mu.state  int32                 4-8   (size  4,  align  4)
    m.mu.sema   uint32                8-12  (size  4,  align  4)

struct rfc2047Decoder, 8 bytes, 0 padding
    CharsetReader  func(…)    0-8  (size  8,  align  8)

Or to only list structs with extra padding:

% structalign regexp/... -with-padding
struct regexp.Regexp, 160 bytes, 13 padding, can save 8 bytes
    expr            string                   0-16   (size 16,  align  8)
    prog            *regexp/syntax.Prog     16-24   (size  8,  align  8)
    onepass         *regexp.onePassProg     24-32   (size  8,  align  8)
    numSubexp       int                     32-40   (size  8,  align  8)
    maxBitStateLen  int                     40-48   (size  8,  align  8)
    subexpNames     []string                48-72   (size 24,  align  8)
    prefix          string                  72-88   (size 16,  align  8)
    prefixBytes     []byte                  88-112  (size 24,  align  8)
    prefixRune      rune                   112-116  (size  4,  align  4)
    prefixEnd       uint32                 116-120  (size  4,  align  4)
    mpool           int                    120-128  (size  8,  align  8)
    matchcap        int                    128-136  (size  8,  align  8)
    prefixComplete  bool                   136-137  (size  1,  align  1)
    cond            regexp/syntax.EmptyOp  137-138  (size  1,  align  1)
    _               «padding»              138-144  (size  6,  align  0)
    minInputLen     int                    144-152  (size  8,  align  8)
    longest         bool                   152-153  (size  1,  align  1)
    _               «padding»              153-160  (size  7,  align  0)

struct regexp.machine, 240 bytes, 14 padding, can save 8 bytes
    re                   *regexp.Regexp         0-8    (size  8,  align  8)
    p                    *regexp/syntax.Prog    8-16   (size  8,  align  8)
    q0.sparse            []uint32              16-40   (size 24,  align  8)
    q0.dense             []regexp.entry        40-64   (size 24,  align  8)
    q1.sparse            []uint32              64-88   (size 24,  align  8)
    q1.dense             []regexp.entry        88-112  (size 24,  align  8)
    pool                 []*regexp.thread     112-136  (size 24,  align  8)
    matched              bool                 136-137  (size  1,  align  1)
    _                    «padding»            137-144  (size  7,  align  0)
    matchcap             []int                144-168  (size 24,  align  8)
    inputs.bytes.str     []byte               168-192  (size 24,  align  8)
    inputs.string.str    string               192-208  (size 16,  align  8)
    inputs.reader.r      io.RuneReader        208-224  (size 16,  align  8)
    inputs.reader.atEOT  bool                 224-225  (size  1,  align  1)
    _                    «padding»            225-232  (size  7,  align  0)
    inputs.reader.pos    int                  232-240  (size  8,  align  8)

About

Print the memory alignment of structs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages