Class: Benchmark::Malloc::Allocation

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/benchmark/malloc/allocation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Allocation

Returns a new instance of Allocation.



24
25
26
27
28
29
30
31
# File 'lib/benchmark/malloc/allocation.rb', line 24

def initialize(object)
  @object      = object
  @memsize     = ObjectSpace.memsize_of(object)
  @class_path  = ObjectSpace.allocation_class_path(object)
  @source_file = ObjectSpace.allocation_sourcefile(object)
  @source_line = ObjectSpace.allocation_sourceline(object)
  @method_id   = ObjectSpace.allocation_method_id(object)
end

Instance Attribute Details

#class_pathObject (readonly)

Returns the value of attribute class_path.



16
17
18
# File 'lib/benchmark/malloc/allocation.rb', line 16

def class_path
  @class_path
end

#memsizeObject (readonly)

The allocated object memory size



14
15
16
# File 'lib/benchmark/malloc/allocation.rb', line 14

def memsize
  @memsize
end

#method_idObject (readonly)

Returns the value of attribute method_id.



22
23
24
# File 'lib/benchmark/malloc/allocation.rb', line 22

def method_id
  @method_id
end

#objectObject (readonly)

The allocated object



11
12
13
# File 'lib/benchmark/malloc/allocation.rb', line 11

def object
  @object
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



18
19
20
# File 'lib/benchmark/malloc/allocation.rb', line 18

def source_file
  @source_file
end

#source_lineObject (readonly)

Returns the value of attribute source_line.



20
21
22
# File 'lib/benchmark/malloc/allocation.rb', line 20

def source_line
  @source_line
end

Instance Method Details

#<=>(other) ⇒ Object



43
44
45
46
# File 'lib/benchmark/malloc/allocation.rb', line 43

def <=>(other)
  @object <=> other.object &&
    @memsize <=> other.memsize
end

#extract(*attributes) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/benchmark/malloc/allocation.rb', line 33

def extract(*attributes)
  attributes.map do |attr|
    if @object.respond_to?(attr)
      @object.public_send(attr)
    else
      public_send(attr)
    end
  end
end