当前位置: 首页>>代码示例>>Golang>>正文


Golang debug.FreeOSMemory函数代码示例

本文整理汇总了Golang中runtime/debug.FreeOSMemory函数的典型用法代码示例。如果您正苦于以下问题:Golang FreeOSMemory函数的具体用法?Golang FreeOSMemory怎么用?Golang FreeOSMemory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FreeOSMemory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: deriveKey

// deriveKey fills out the Key field.
func (sk *SecretKey) deriveKey(password *[]byte) error {
	key, err := scrypt.Key(*password, sk.Parameters.Salt[:],
		sk.Parameters.N,
		sk.Parameters.R,
		sk.Parameters.P,
		len(sk.Key))
	if err != nil {
		return err
	}
	copy(sk.Key[:], key)
	zero.Bytes(key)

	// I'm not a fan of forced garbage collections, but scrypt allocates a
	// ton of memory and calling it back to back without a GC cycle in
	// between means you end up needing twice the amount of memory.  For
	// example, if your scrypt parameters are such that you require 1GB and
	// you call it twice in a row, without this you end up allocating 2GB
	// since the first GB probably hasn't been released yet.
	debug.FreeOSMemory()

	// I'm not a fan of forced garbage collections, but scrypt allocates a
	// ton of memory and calling it back to back without a GC cycle in
	// between means you end up needing twice the amount of memory.  For
	// example, if your scrypt parameters are such that you require 1GB and
	// you call it twice in a row, without this you end up allocating 2GB
	// since the first GB probably hasn't been released yet.
	debug.FreeOSMemory()

	return nil
}
开发者ID:decred,项目名称:dcrwallet,代码行数:31,代码来源:snacl.go

示例2: FreeMemory

// Starts another thread to perform OS memory freeing
func FreeMemory(durationMinutes int) {
	go func() {
		for {
			debug.FreeOSMemory()
			debug.FreeOSMemory()
			time.Sleep(time.Duration(durationMinutes) * time.Minute)
		}
	}()
}
开发者ID:infoassure,项目名称:nsrls,代码行数:10,代码来源:misc.go

示例3: write

func write(wr writeRequest, id string) {
	cmds, idArr, bufTypeArr := createCommands(wr, id)

	qr := qReport{
		Cmd: "Queued",
		//Type: bufTypeArr,
		Ids:  idArr,
		D:    cmds,
		QCnt: wr.p.itemsInBuffer,
		Port: wr.p.portConf.Name,
	}
	json, _ := json.Marshal(qr)
	h.broadcastSys <- json

	// now send off the commands to the appropriate channel
	for index, cmdToSendToChannel := range cmds {
		//cmdIdCtr++
		//cmdId := "fakeid-" + strconv.Itoa(cmdIdCtr)
		cmdId := idArr[index]
		if bufTypeArr[index] == "Buf" {
			log.Println("Send was normal send, so sending to wr.p.sendBuffered")
			wr.p.sendBuffered <- Cmd{cmdToSendToChannel, cmdId, false, false}
		} else {
			log.Println("Send was sendnobuf, so sending to wr.p.sendNoBuf")
			wr.p.sendNoBuf <- Cmd{cmdToSendToChannel, cmdId, true, false}
		}
	}

	// garbage collect
	if *gcType == "max" {
		debug.FreeOSMemory()
	}

}
开发者ID:ndoty,项目名称:serial-port-json-server,代码行数:34,代码来源:serial.go

示例4: fillseq

func fillseq() {
	dbname := os.Args[0] + ".db"
	f, err := os.OpenFile(dbname, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666)
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		f.Close()
		os.Remove(f.Name())
	}()

	filer := lldb.NewSimpleFileFiler(f)
	a, err := lldb.NewAllocator(filer, &lldb.Options{})
	if err != nil {
		log.Println(err)
		return
	}

	a.Compress = true
	b, _, err := lldb.CreateBTree(a, nil)
	if err != nil {
		log.Println(err)
		return
	}

	var keys [N][16]byte
	for i := range keys {
		binary.BigEndian.PutUint32(keys[i][:], uint32(i))
	}

	debug.FreeOSMemory()
	t0 := time.Now()
	for _, key := range keys {
		if err = b.Set(key[:], value100); err != nil {
			log.Println(err)
			return
		}
	}
	if err := filer.Sync(); err != nil {
		log.Println(err)
		return
	}
	var ms runtime.MemStats
	runtime.ReadMemStats(&ms)

	d := time.Since(t0)
	fi, err := f.Stat()
	if err != nil {
		log.Println(err)
		return
	}

	secs := float64(d/time.Nanosecond) / float64(time.Second)
	sz := fi.Size()
	fmt.Printf("fillseq      :%19v/op;%7.1f MB/s (%g secs, %d bytes)\n", d/N, float64(sz)/secs/1e6, secs, sz)
	nn, bytes := bufs.GCache.Stats()
	fmt.Printf("%d %d\n", nn, bytes)
	fmt.Printf("%+v\n", ms)
}
开发者ID:rfistman,项目名称:camlistore,代码行数:60,代码来源:main.go

示例5: TestPartGC

func (s *MultipartTestSuite) TestPartGC() {
	part := NewPart()
	wrapper := NewDataWrapper()
	part.SetContentObject(wrapper)
	s.part.AddPart(part)

	allParts := s.part.GetPart(0)
	allParts2 := s.part.GetPart(0)

	_, ok := allParts.(Part)
	_, ok = allParts2.(Part)

	allParts = nil
	part = nil
	wrapper = nil
	debug.FreeOSMemory()

	// Try to access allParts2.
	// This should not fail under valgrind
	typeString := "multipart/mixed"
	boundary := "--foo++bar==foo--"
	contentType := NewContentTypeFromString(typeString)
	contentType.SetParameter("boundary", boundary)
	allParts2.SetContentType(contentType)

	assert.True(s.T(), ok)
}
开发者ID:partkyle,项目名称:go-gmime,代码行数:27,代码来源:multipart_test.go

示例6: benchmarkPrev

func benchmarkPrev(b *testing.B, n int) {
	t := TreeNew(cmp)
	for i := 0; i < n; i++ {
		t.Set(i, 0)
	}
	debug.FreeOSMemory()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		en, err := t.SeekLast()
		if err != nil {
			b.Fatal(err)
		}

		m := 0
		for {
			if _, _, err = en.Prev(); err != nil {
				break
			}
			m++
		}
		if m != n {
			b.Fatal(m)
		}
	}
}
开发者ID:nikandfor,项目名称:b,代码行数:25,代码来源:all_test.go

示例7: gcRunner

//
// for test only, run GC for profile GC in huge map
func (eng *Engine) gcRunner(interval int) {
	tk := time.NewTicker(time.Duration(interval) * time.Second)
	defer tk.Stop()
	var pre, cnt int64
	var iopre, iocnt int64
	var rwpre, rwcnt int64
	var norepeatgc bool
	for {
		//
		cnt = atomic.LoadInt64(eng.aliveCount)
		iocnt = atomic.LoadInt64(eng.newCount)
		rwcnt = atomic.LoadInt64(eng.rwCount)
		if cnt > 0 {
			if eng.conf.gctest && (pre != cnt || iopre != iocnt || rwpre != rwcnt) {
				fmt.Printf("GC with %d connections.\n", cnt)
				runtime.GC()
				//fmt.Printf("GC done.\n")
				pre = cnt
			}
			norepeatgc = false
		} else if norepeatgc == false {
			// even if eng.conf.gctest == false, still call FreeOSMemory when connections == 0
			norepeatgc = true
			fmt.Printf("FreeOSMemory with %d connections.\n", cnt)
			// free memory
			debug.FreeOSMemory()
			//fmt.Printf("FreeOSMemory done.\n")
			pre = cnt
		}
		<-tk.C
	}
}
开发者ID:jmptrader,项目名称:tcpengine,代码行数:34,代码来源:tcpengine.go

示例8: benchmarkNext

func benchmarkNext(b *testing.B, n int) {
	t := TreeNew(cmp)
	for i := int64(0); i < int64(n); i++ {
		t.Set(i, struct{}{})
	}
	debug.FreeOSMemory()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		en, err := t.SeekFirst()
		if err != nil {
			b.Fatal(err)
		}

		m := 0
		for {
			if _, _, err = en.Next(); err != nil {
				break
			}
			m++
		}
		if m != n {
			b.Fatal(m)
		}
	}
	b.StopTimer()
	t.Close()
}
开发者ID:JesseLivingston,项目名称:cayley,代码行数:27,代码来源:keys_test.go

示例9: monitor

func monitor() {
	c := time.Tick(1 * time.Second)
	mem := new(runtime.MemStats)
	origPct := debug.SetGCPercent(100)
	debug.SetGCPercent(origPct)
	for _ = range c {
		runtime.ReadMemStats(mem)
		mu.Lock()
		defer mu.Unlock()
		if tSize < 0 {
			continue
		}
		// Occupancy fraction: 70%. Don't GC before hitting this.
		softLimit := float64(tSize) * 0.7
		pct := softLimit / float64(mem.Alloc) * 100
		fmt.Printf("gctune: pct: %0.5f, target: %d, softLimit: %0.2f, Alloc: %d, Sys: %d\n", pct, tSize, softLimit, mem.Alloc, mem.Sys)
		if pct < 50 {
			// If this is too low, GC frequency increases too much.
			pct = 50
		}
		debug.SetGCPercent(int(pct))
		if mem.Sys > uint64(tSize*70/100) {
			fmt.Println("freeing")
			debug.FreeOSMemory()
		}
	}
}
开发者ID:nictuku,项目名称:gctune,代码行数:27,代码来源:gctune.go

示例10: receiveDecrypt

func receiveDecrypt(conn net.Conn) (Message, error) {
	// Our work is:
	// (receive) -> [de-GOB] -> [DECRYPT] -> [de-GOB] -> msg

	// Receive data and de-serialize to get the encrypted message
	encMsg := new([]byte)
	receive := gob.NewDecoder(conn)
	if err := receive.Decode(encMsg); err != nil {
		return Message{}, err
	}

	// Create decrypter and pass it the encrypted message
	r := bytes.NewReader(*encMsg)
	decrypter, err := saltsecret.NewReader(r, conf.Key, saltsecret.DECRYPT, false)
	if err != nil {
		return Message{}, err
	}

	// Read unencrypted serialized message and de-serialize it
	msg := new(Message)
	dec := gob.NewDecoder(decrypter)
	if err = dec.Decode(msg); err != nil {
		return Message{}, err
	}
	debug.FreeOSMemory()
	return *msg, nil
}
开发者ID:andmarios,项目名称:bashistdb,代码行数:27,代码来源:encryptcomm_lowmem.go

示例11: encryptDispatch

func encryptDispatch(conn net.Conn, m Message) error {
	// We want to sent encrypted data.
	// In order to encrypt, we need to first serialize the message.
	// In order to sent/receive hassle free, we need to serialize the encrypted message
	// So: msg -> [GOB] -> [ENCRYPT] -> [GOB] -> (dispatch)

	// Create encrypter
	var encMsg bytes.Buffer
	encrypter, err := saltsecret.NewWriter(&encMsg, conf.Key, saltsecret.ENCRYPT, true)
	if err != nil {
		return err
	}

	// Serialize message
	enc := gob.NewEncoder(encrypter)
	if err = enc.Encode(m); err != nil {
		return err
	}

	// Flush encrypter to actuall encrypt the message
	if err = encrypter.Flush(); err != nil {
		return err
	}

	// Serialize encrypted message and dispatch it
	dispatch := gob.NewEncoder(conn)
	if err = dispatch.Encode(encMsg.Bytes()); err != nil {
		return err
	}
	debug.FreeOSMemory()
	return nil
}
开发者ID:andmarios,项目名称:bashistdb,代码行数:32,代码来源:encryptcomm_lowmem.go

示例12: cmpStat

func (cmc *FileMonitor) cmpStat(f_old map[string]os.FileInfo, f_new map[string]os.FileInfo) {
	var fo FileOp
	for i, v := range f_old {
		if in, ok := f_new[i]; ok {
			if !v.ModTime().Equal(in.ModTime()) {
				// update
				f_old[i] = in
				delete(f_new, i)
				fo.fname = i
				fo.op = OP_MOD
				cmc.f <- fo
			}
			delete(f_new, i)
			// no changed
		} else {
			delete(f_old, i)
			fo.fname = i
			fo.op = OP_DEL
			cmc.f <- fo
			// delete
		}
	}

	for i, v := range f_new {
		// add
		f_old[i] = v
		delete(f_new, i)
		fo.fname = i
		fo.op = OP_ADD
		cmc.f <- fo
	}
	debug.FreeOSMemory()
}
开发者ID:hwch,项目名称:fmonitor,代码行数:33,代码来源:fmonitor.go

示例13: removeConnection

func (chat *Chat) removeConnection(toRemove *Connection) {
	for i, el := range chat.connections {
		if *toRemove == el {
			//chat.connections = append(chat.connections[:i], chat.connections[i+1:]...)

			// THE FOLLOWING IS UNNECESSARILY COMPLEX AND ONLY TO RULE OUT A MemLeak
			copy(chat.connections[i:], chat.connections[i+1:])
			chat.connections[len(chat.connections)-1] = Connection{} //nil // or the zero value of T
			chat.connections = chat.connections[:len(chat.connections)-1]

			// THE FOLLOWING IS UNNECESSARILY COMPLEX AND ONLY TO RULE OUT A MemLeak
			if cap(chat.connections) > 2*len(chat.connections) {
				fmt.Println("SHRINK")
				shrink := make([]Connection, len(chat.connections))
				copy(shrink, chat.connections)
				chat.connections = shrink
				debug.FreeOSMemory()
			}

			break
		}
	}
	// DEBUG::
	fmt.Println("Num GoRoutines", runtime.NumGoroutine())
	fmt.Println("Len(connections)", len(chat.connections))
	fmt.Println("Cap(connections)", cap(chat.connections))
	GoRuntimeStats()
}
开发者ID:SittingIdle,项目名称:chat,代码行数:28,代码来源:engine.go

示例14: TestDispositionIsAttachment

func TestDispositionIsAttachment(t *testing.T) {
	loop := 1
	for i := 0; i < loop; i++ {
		// Case 1: not an attachment
		contentString := ""
		cd := NewContentDispositionFromString(contentString)
		assert.False(t, cd.IsAttachment())

		// Case 2: is an attachment
		contentString = "attachment"
		cd = NewContentDispositionFromString(contentString)
		assert.True(t, cd.IsAttachment())

		// Case 3: is an inline attachment
		contentString = "inline"
		cd = NewContentDispositionFromString(contentString)
		assert.True(t, cd.IsAttachment())

		// Case 4: anything is an attachment for now
		contentString = "bogus"
		cd = NewContentDispositionFromString(contentString)
		assert.True(t, cd.IsAttachment())
	}
	debug.FreeOSMemory()
}
开发者ID:partkyle,项目名称:go-gmime,代码行数:25,代码来源:content_disposition_test.go

示例15: RebalanceGC

// RebalanceGC rebalances the tree and runs the garbage collector.
func (st *SimpleTree) RebalanceGC() *SimpleTree {
	st.Rebalance()
	runtime.GC()
	debug.FreeOSMemory()

	return st
}
开发者ID:teh-cmc,项目名称:freetree,代码行数:8,代码来源:simpletree.go


注:本文中的runtime/debug.FreeOSMemory函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。