Module: HeapInfo::Ext::String::InstanceMethods

Defined in:
lib/heapinfo/ext/string.rb

Overview

Methods to be mixed into String

Instance Method Summary collapse

Instance Method Details

#to_chunk(bits: 64, base: 0) ⇒ HeapInfo::Chunk

Convert string to a Chunk.

Parameters:

  • [Integer] (Hash)

    a customizable set of options

Returns:


12
13
14
15
16
# File 'lib/heapinfo/ext/string.rb', line 12

def to_chunk(bits: 64, base: 0)
  size_t = bits / 8
  dumper = ->(addr, len) { self[addr - base, len] }
  Chunk.new(size_t, base, dumper)
end

#to_chunks(bits: 64, base: 0) ⇒ HeapInfo::Chunks

Convert string to array of Chunk.

Parameters:

  • [Integer] (Hash)

    a customizable set of options

Returns:


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/heapinfo/ext/string.rb', line 22

def to_chunks(bits: 64, base: 0)
  size_t = bits / 8
  chunks = Chunks.new
  cur = 0
  while cur + size_t * 2 <= length
    now_chunk = self[cur, size_t * 2].to_chunk
    sz = now_chunk.size
    chunks << self[cur, sz + 1].to_chunk(bits: bits, base: base + cur) # +1 for dump prev_inuse
    cur += sz
  end
  chunks
end