Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/leeychee/mlayout

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/leeychee/mlayout

  • v0.0.0-20160411033804-65b27d356572
  • Source
  • Go
  • Socket score

Version published
Created
Source

Golang type's memory layout

GoDoc Build Status

Package mlayout try to describe golang type's memory layout, especially struct's. According to language's implements, different order of fields use different memory layout, so different memory use ratio sometimes.

Here is a simple example, two structs with different fields order.

type t1 struct {
	a bool
	b int
	c bool
}

type t2 struct {
	a bool
	b bool
	c int
}

fmt.Printf("t1:\n%s\n", mlayout.Layoutof(t1{}))
fmt.Printf("t2:\n%s", mlayout.Layoutof(t2{}))
// Output:
// t1:
// x_______
// xxxxxxxx
// x_______
// t2:
// xx______
// xxxxxxxx

So we could try to imporve the struct's use ratio of memory with this, by adjusting struct's fields order.

Installation

go get -u github.com/leeychee/mlayout

Usage

For now, you can use the lib to get a type's use ratio of memory, and ascii image.

type t1 struct {
	a bool
	b int
	c bool
}
l := mlayout.Layoutof(t1{})
fmt.Printf("t1's use ratio is %.2f", l.UseRatio())
fmt.Printf("t1's acsii image is: \n%s\n", l)

TODO

Maybe, we could build a cmd tool to analysis structs, and give some advices.

FAQs

Package last updated on 11 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc