class HeapInfo::UnsortedBin
Class for record unsorted bin type chunk.
Attributes
bk[R]
@return [Integer]
Public Class Methods
new(*args)
click to toggle source
Instantiate a {HeapInfo::UnsortedBin} object.
@param [Mixed] args See {HeapInfo::Chunk} for more information.
Calls superclass method
HeapInfo::Fastbin::new
# File lib/heapinfo/arena.rb, line 166 def initialize(*args) super @bk = Helper.unpack(size_t, @data[@size_t, @size_t]) end
Public Instance Methods
inspect(size: 2)
click to toggle source
@param [Integer] size
At most expand size. For +size = 2+, the expand list would be <tt>bk, bk, bin, fd, fd</tt>.
@return [String] Unsorted bin layouts wrapper with color codes.
# File lib/heapinfo/arena.rb, line 174 def inspect(size: 2) list = link_list(size) return '' if list.size <= 1 && Helper.class_name(self) != 'UnsortedBin' # bad.. title + pretty_list(list) + "\n" end
link_list(expand_size)
click to toggle source
Return the double link list with bin in the center.
The list will like +[…, bk of bk, bk of bin, bin, fd of bin, fd of fd, …]+. @param [Integer] expand_size
At most expand size. For +size = 2+, the expand list would be <tt>bk, bk, bin, fd, fd</tt>.
@return [Array<Integer>] The linked list.
# File lib/heapinfo/arena.rb, line 205 def link_list(expand_size) list = [@base] # fd work = proc do |ptr, nxt, append| sz = 0 dup = {} while ptr != @base && sz < expand_size append.call(ptr) break if ptr.nil? || dup[ptr] # invalid or duplicated pointer dup[ptr] = true ptr = __send__(nxt, ptr) sz += 1 end end work.call(@fd, :fd_of, ->(ptr) { list << ptr }) work.call(@bk, :bk_of, ->(ptr) { list.unshift(ptr) }) list end
pretty_list(list)
click to toggle source
Wrapper the doubly linked list with color codes. @param [Array<Integer>] list The list from {#link_list}. @return [String] Wrapper with color codes.
# File lib/heapinfo/arena.rb, line 183 def pretty_list(list) center = nil list.map.with_index do |c, idx| next center = Helper.color('[self]', sev: :bin) if c == @base color_c = Helper.color(format('%#x', c)) fwd = fd_of(c) next "#{color_c}(invalid)" if fwd.nil? # invalid c bck = bk_of(c) if center.nil? # bk side format('%s%s', color_c, fwd == list[idx + 1] ? nil : Helper.color(format('(%#x)', fwd))) else # fd side format('%s%s', bck == list[idx - 1] ? nil : Helper.color(format('(%#x)', bck)), color_c) end end.join(' === ') end