[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:5992] Mem overhead of singleton (ProgRuby chapt 19 q)

From: Robert Feldt <feldt@...>
Date: 2000-11-02 14:39:58 UTC
List: ruby-talk #5992
Hi,

The "Programming Ruby" book finally arrived here in Sweden yesterday and
its a great book. Thanks a lot Dave and Andy! I sincerely hope that this
will be the start of the Ruby world domination era (well... :-)).

I've been working with class decoration a bit and find your piece on
"Class and Module Definitions" interesting. However, my q to you and
(possibly other Ruby gurus?) are what effect the "performance enhancement
based on Tadayoshi Funaba's data module" has on the mem usage?

ie.:

class Module
  private

  def id_or_name_to_name(idOrName)
    begin
      idOrName = idOrName.id2name
    rescue NameError
    end
    idOrName
  end

  # Note: Not thread safe?!
  def eval_once_then_cache(*methods)
    begin
      eotc_counter = module_eval "@@__eotc_counter__"
    rescue NameError
      eotc_counter = module_eval("@@__eotc_counter__ = 0")
    end
    for method in methods
      method = id_or_name_to_name(method)
      old_method = "__eotc_oldmethod_#{(eotc_counter += 1)}__"
      module_eval <<-"end_eval"
        alias_method :#{old_method}, :#{method}
	def #{method}(*args, &block)
	  def self.#{method}(*args, &block)
	    @#{old_method}
	  end
	  @#{old_method} = #{old_method}(*args, &block)
	end
      end_eval
    end
    module_eval "@@__eotc_counter__ = #{eotc_counter}"
  end
end

I guess the effect of having a class C with methods
"declared" eval_once_then_cache is that each instance will contain their
own singleton method returning the cached value => performance enhancement
but extra mem used.

Is the extra mem significant or will it only be noticed if huge amounts of
objects of class C are floating around?

Basically this boils down to how many bytes are needed for a
(small) singleton method like the one above? What kind of overhead are
involved?

Regards,

Robert


In This Thread

Prev Next