[#11156] How to delete methods from superclass? — Clemens Hintze <c.hintze@...>

Hello,

25 messages 1998/12/01
[#11157] Re: How to delete methods from superclass? — matz@... (Yukihiro Matsumoto) 1998/12/01

Hi, Clemens.

[#11176] English List [Re: How to delete methods from superclass?] — gotoken@... (GOTO Kentaro) 1998/12/01

In message "[ruby-list:11157] Re: How to delete methods from superclass?"

[#11250] Ruby 用語集 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

25 messages 1998/12/08

[#11269] 京都 (Re: [ruby-dev:3789] Re: List()) — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

21 messages 1998/12/11
[#11299] Re: 京都 — MAEDA Shugo <shugo@...> 1998/12/12

前田です。

[#11393] mod_ruby — shugo@... (Shugo Maeda)

前田です。

28 messages 1998/12/21
[#11394] Re: mod_ruby — matz@... (Yukihiro Matsumoto) 1998/12/21

まつもと ゆきひろです

[#11398] Re: mod_ruby — shugo@... (Shugo Maeda) 1998/12/21

前田です。

[#11399] RE: mod_ruby — OZAWA Sakuro <crouton@...> 1998/12/21

さくです。

[#11408] Re: Be port — shugo@... (Shugo Maeda) 1998/12/22

前田です。

[#11464] ruby and IDE — Noritsugu Nakamura <nnakamur@...>

18 messages 1998/12/27
[#11465] goto (Re: ruby and IDE) — ttate@... 1998/12/27

立石です。

[ruby-list:11276] pstore.rb

From: keiju@... (Keiju ISHITSUKA)
Date: 1998-12-11 05:39:06 UTC
List: ruby-list #11276
けいじゅ@日本ラショナルソフトウェアです.

pstoreに関してですが, transactionをコミットしたあとでも @table の参照
が残ったままですよね? marshalした後, @table = nil とした方がよかないで
すか? 今のままだと, @tableの内容がGCの対象になりません.

そんでもって, いいの考えました. キャッシュ機能付きPStoreです.

コミットした後, @tableの参照しているインスタンスをWeakRefを用いて保存
しておいて, 次にtransactionを開始した時に, GCされずに残っていたらそれ
をそのまま使う方法です. 

こうすると, 読み込みのコストが下がる可能性が高くなっるのでよいと思いま
せん?

-- ここから
#
# How to use:
#
# db = PStoreWC.new("/tmp/foo")
# db.transaction do
#   p db.roots
#   ary = db["root"] = [1,2,3,4]
#   ary[0] = [1,1.5]
# end

# db.transaction do
#   p db["root"]
# end

require "pstore"
require "weakref"

class PStoreWC < PStore
  
  def initialize(file)
    super
    @cache = nil
  end

  def transaction
    raise PStore::Error, "nested transaction" if @transaction
    begin
      @transaction = true
      value = file = nil
      if @cache and @cache.weakref_alive?
	@table = @cache[]
      else
	begin
	  File::open(@filename, "r") do |file|
	    @table = Marshal.load(file)
	  end
	rescue Errno::ENOENT
	  @table = {}
	end
      end
      begin
	catch(:pstore_abort_transaction) do
	  value = yield(self)
	end
      rescue Exception
	@abort = true
	raise
      ensure
	unless @abort
	  begin
	    File::rename @filename, @filename+"~"
	  rescue Errno::ENOENT
	    no_orig = true
	  end
	  begin
	    File::open(@filename, "w") do |file|
	      Marshal::dump(@table, file)
	      @cache = WeakRef.new(@table)
	    end
	  rescue
	    File::rename @filename+"~", @filename unless no_orig
	  end
	end
	@abort = false
      end
    ensure
      @transaction = false
    end
    value
  end
end

PSWC = PStoreWC

if __FILE__ == $0
  db = PStoreWC.new("/tmp/foo")
  db.transaction do
    p db.roots
    ary = db["root"] = [1,2,3,4]
    ary[0] = [1,1.5]
  end

  db.transaction do
    p db["root"]
  end

  ObjectSpace.garbage_collect

  db.transaction do
    p db["root"]
  end
  
end


__
..............................石塚 圭樹@日本ラショナルソフトウェア...
----------------------------------->> e-mail: keiju@rational.com <<---

In This Thread

Prev Next