Giter Site home page Giter Site logo

gmmpool's Introduction

gmmpool

A multi level memory pool for Golang:

The design thoughts are detailed in golang multi-level memory pool design and implemention(in Chinese🇨🇳).

Installation

go get github.com/liudanking/gmmpool

Usage

package main

import (
	"bytes"
	"log"

	"github.com/liudanking/gmmpool"
)

func main() {
	pool := gmmpool.NewMultiLevelPool([]gmmpool.PoolOpt{
		gmmpool.PoolOpt{Num: 10, Size: 1024},     // level 0
		gmmpool.PoolOpt{Num: 10, Size: 1024 * 2}, // level 1
	})

	buf := pool.Get(1025)
	defer pool.Put(buf)
	data, err := buf.ReadAll(bytes.NewReader(make([]byte, 8)))
	if err != nil {
		log.Fatal(err)
	}
	log.Print(data)
}

Benchmark (compared with ioutil.ReadAll, x19 speed up)

BenchmarkStdReadAll-4             200000          5969 ns/op
BenchmarkMultiLevelPool-4        5000000           311 ns/op

Credit

goim

疑问:

预分配大Node slice,Node里有pre和next,这样搞array内链表。释放时没有做全部解引用,只在Node slice首尾两端置nil。这个搞法会导致你说的这个情况。Node slice在应用层看是独立的单元,在runtime看,就是一个object,object内部的引用,也会计入当前分配内存,这样gc阈值被放大了。 arr=[a,b,c,d] a->b->c->d,这样有三个引用关系,gc那边统计就是 len(arr)*3。 如果是简单的a->b->c->d,gc那边统计的就是3

gmmpool's People

Contributors

jursonmo avatar liudanking avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.