class Marshal::Structure::AllocationCounter

Counts allocations necessary to load the stream. The number of allocations may be less as symbols (e.g. for object instance variables) may already exist.

Allocation counts are determined as follows:

Public Class Methods

new(tokens) click to toggle source

Creates a new AllocationCounter for tokens

# File lib/marshal/structure/allocation_counter.rb, line 21
def initialize tokens
  @tokens = tokens

Public Instance Methods

count() click to toggle source

Counts objects allocated from the stream.

# File lib/marshal/structure/allocation_counter.rb, line 28
def count
  token =

  case token
  when :nil, :true, :false          then 0
  when :array                       then count_array
  when :bignum                      then count_bignum
  when :class, :module, :module_old then count_class
  when :data                        then count_data
  when :extended                    then count_extended
  when :fixnum, :link, :symbol_link then; 0
  when :float                       then count_float
  when :hash                        then count_hash
  when :hash_default                then count_hash_default
  when :object                      then count_object
  when :regexp                      then count_regexp
  when :string                      then count_string
  when :struct                      then count_struct
  when :symbol                      then count_symbol
  when :user_class                  then count_extended
  when :user_defined                then count_user_defined
  when :user_marshal                then count_user_marshal
  when :instance_variables          then count + count_instance_variables
    raise Marshal::Structure::Error, "bug: unknown token #{token.inspect}"
rescue Marshal::Structure::EndOfMarshal
  raise ArgumentError, 'marshal data too short'