public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
rubinius / lib / cheney_heap.rb
100644 30 lines (25 sloc) 0.459 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'heap'
 
class CheneyHeap < Heap
  def initialize(size)
    super
    @scan = @address
    @next = @address
  end
  
  attr_accessor :scan, :next
  
  def allocate(size)
    addr = @next
    @next += size
    return addr
  end
  
  def fully_scanned?
    @scan == @next
  end
  
  def unscanned_objects
    return if fully_scanned?
    until @scan >= @next
      obj = RObject.new(@scan)
      yield obj
      @scan += obj.memory_size
    end
  end
end