class ThreadLocalBuffer

A thread local buffer manager. Provide's each thread with a single pre-allocated IO buffer. IMPORTANT: as these buffers are indexed in a hashtable they will not be freed until the application closes. If a thread needs to free the memory its buffer is using, it must call delete_buffer and ensure it has no references to the buffer.

A thread local buffer manager. Provide's each thread with a single pre-allocated IO buffer. IMPORTANT: as these buffers are indexed in a hashtable they will not be freed until the application closes. If a thread needs to free the memory its buffer is using, it must call delete_buffer and ensure it has no references to the buffer.

Constants

POWER
SIZE

Public Class Methods

get_buffer() click to toggle source

Return the thread's buffer.

# File lib/ec2/amitools/util.rb, line 38
def ThreadLocalBuffer.get_buffer
  @@buffers.synchronize do
    @@buffers[Thread.current] = new_buffer unless @@buffers.has_key?( Thread.current )
    @@buffers[Thread.current]
  end
end

Private Class Methods

new_buffer() click to toggle source
# File lib/ec2/amitools/util.rb, line 54
def ThreadLocalBuffer.new_buffer
  buffer = String.new
  buffer = Format::hex2bin( '00' )
  POWER.times { buffer << buffer }
  buffer
end

Public Instance Methods

delete_buffer(buffer) click to toggle source

Delete the threads buffer.

# File lib/ec2/amitools/util.rb, line 48
def delete_buffer buffer
  @@buffers.delete buffer
end