# File lib/nice-ffi/struct.rb, line 331
  def initialize( val, options={} )
    # Stores certain kinds of member values so that we don't need
    # to create a new object every time they are read.
    @member_cache = {}

    options = {:autorelease => true}.merge!( options )

    case val

    when Hash
      super(FFI::Buffer.new(size))
      init_from_hash( val )         # Read the values from a Hash.

    # Note: plain "Array" would mean FFI::Struct::Array in this scope.
    when ::Array
      super(FFI::Buffer.new(size))
      init_from_array( val )        # Read the values from an Array.

    when String
      super(FFI::Buffer.new(size))
      init_from_bytes( val )        # Read the values from a bytestring.

    when self.class
      super(FFI::Buffer.new(size))
      init_from_bytes( val.to_bytes ) # Read the values from another instance.

    when FFI::Pointer, FFI::Buffer
      val = _make_autopointer( val, options[:autorelease] )

      # Normal FFI::Struct behavior to wrap the pointer.
      super( val )

    else
      raise TypeError, "cannot create new #{self.class} from #{val.inspect}"

    end
  end