Method: PEROBS::SpaceManager#get_space
- Defined in:
- lib/perobs/SpaceManager.rb
#get_space(length) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/perobs/SpaceManager.rb', line 117 def get_space(length) # We use a simple exact fit strategy. All attempts to use a more # elaborate scheme were actually less efficient. Non-exact matches # generate new spaces for the remainder and fragment the blob file with # lots of unusable small spaces. Most applications seem to have # clustered their blob sizes around a number of popular sizes. So exact # match is very efficient to implement and results in the highest # probability that a space will be reused soon. list_entry_addr = @index.get(length) if list_entry_addr blob = @list.retrieve_blob(list_entry_addr) space_address, next_entry_addr = blob.unpack('QQ') @list.delete_blob(list_entry_addr) if next_entry_addr > 0 # Update the index entry for the length to point to the # following space list entry. @index.insert(length, next_entry_addr) else # The space list for this length is empty. Remove the entry # from the index. @index.remove(length) end @recycled_spaces += 1 # We return the length to remain compatible with the old SpaceTree # API. return [ space_address, length ] end @failed_requests += 1 nil end |