亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

運行時:goroutine 堆棧超過 1000000000 字節限制,當將結構保存到 json 時

運行時:goroutine 堆棧超過 1000000000 字節限制,當將結構保存到 json 時

Go
喵喵時光機 2023-06-05 17:20:17
我已經定義了一個 Trie 數據結構的 go struct。type Node struct {Val      runeIsWord   boolIsRoot   boolParent   *NodeChildren map[rune]*Node}type Trie struct {Root *Node}trie := algorithms.InitTrie()但是,它會引發錯誤runtime: goroutine stack exceeds 1000000000-byte limitfatal error: stack overflowruntime stack:runtime.throw(0x10e9426, 0xe)/usr/local/go/src/runtime/panic.go:605 +0x95runtime.newstack(0x0)/usr/local/go/src/runtime/stack.go:1050 +0x6e1runtime.morestack()/usr/local/go/src/runtime/asm_amd64.s:415 +0x86當我插入一些單詞并將其保存到 json 文件中時。fmt.Println(json.Marshal(&trie))
查看完整描述

1 回答

?
Helenr

TA貢獻1780條經驗 獲得超4個贊

問題是每個人Node都引用了它的父母,以及它的孩子。因此,當它對一個孩子進行編碼時,對于父字段,它會再次對父字段進行編碼,對于該父字段,它會再次對子字段進行編碼,等等。一個簡單的解決方案是在編碼時不使用該Parent字段

Parent   *Node `json:"-"`

這將阻止循環。

https://play.golang.org/p/BdVgMNjlZOa


查看完整回答
反對 回復 2023-06-05
  • 1 回答
  • 0 關注
  • 316 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號