2012-10-22 18:30
浏览 62

Go中有与Java的String intern函数等效的功能吗?

Is there an equivalent to Java's String intern function in Go?

I am parsing a lot of text input that has repeating patterns (tags). I would like to be memory efficient about it and store pointers to a single string for each tag, instead of multiple strings for each occurrence of a tag.

图片转代码服务由CSDN问答提供 功能建议

Go中是否有与Java的String intern函数等效的文件?

I 解析了很多具有重复模式(标记)的文本输入。 我想提高内存效率,并为每个标签存储指向单个字符串的指针,而不是为每次出现标签存储多个字符串。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douqin1932 2012-10-22 20:00

    I think that for example Pool and GoPool may fulfill your needs. That code solves one thing which Stephen's solution ignores. In Go, a string value may be a slice of a bigger string. Scenarios are where it doesn't matter and scenarios are where that is a show stopper. The linked functions attempt to be on the safe side.

    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题