处理GO中的大内存块

huangapple go评论78阅读模式
英文:

Dealing with big memory chunks in GO

问题

有没有描述Go如何有效处理以下用例的指南:

  1. 应用程序接收到包含分隔名称的1亿个字符串,每个名称最长为1M。例如:"Ben;Aaron;Rich;Donna..."。需要按字母顺序打印出相同的名称,而不会显著增加内存使用量(假设总共使用不超过150M的RAM)。
  2. 给定两个具有大内存块的集合(每个集合最多1M),需要有效地将几个块从一个集合移动到另一个集合(不需要显著的额外内存分配)。
英文:

Are there any guidelines which describe how Go may effectively address following use cases :

  1. Application receives 100M string consisting of delimited names, each name up to 1M long. E.g.: "Ben;Aaron;Rich;Donna...". Need to print out the same names in alphabet order without significant memory usage increase (let's say up to 150M RAM used in total)
  2. Given two collections with huge memory chunks (let's say up to 1M each) and need to effectively move few chunks from one collection to the other (without significant additional memory allocation)

答案1

得分: 1

  1. 我假设你不能修改字符串,所以字符串是不可变的(不是 []byte),因为去除任何这样的限制会使任务变得简单。如果是这样的话,你可以创建一个额外的结构,其中包含字符串索引,并在其中进行排序(n*log(n) 时间复杂度)。只需实现 Less 方法,使其比较原始字符串中的子字符串。
  2. 第二个问题很简单 - 只需使用链表。
英文:
  1. I assume that you cannot modify the string so the string and the string is immutable (not []byte), because removing any of such limitations makes the task trivial. If so, then you can create additional structure with string indices and sort in it (n*log(n)) time. Just implement Less in a way it compares the substrings in original string.
  2. The second one is trivial - just use linked list.

huangapple
  • 本文由 发表于 2015年8月2日 18:59:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/31771170.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定