Thread-Serialize-0.07 > Thread::Serialize

名前

Thread::Serialize - スレッド間のデータ構造をシリアル化

概要

  use Thread::Serialize;    # freeze()とthaw()をエクスポート

  use Thread::Serialize (); # must call fully qualified subs

  my $frozen = freeze( any data structure );
  any data structure = thaw( $frozen );

説明

                  *** A note of CAUTION ***

 This module only functions on Perl versions 5.8.0 and later.
 And then only when threads are enabled with -Dusethreads.  It
 is of no use with any version of Perl before 5.8.0 or without
 threads enabled.

                  *************************


                  *** 注   意   書   き ***

 このモジュールは、Perlのバージョン5.8.0以降で、かつ、-Dusethreads
 オプションでスレッドが有効になっている場合にのみ機能する。5.8.0以前、
 あるいはスレッドが有効になっていない場合は、使うことができない。

                  *************************

The Thread::Serialize module is a library for centralizing the routines used to serialize data-structures between threads. Because of this central location, other modules such as Thread::Conveyor, Thread::Pool or Thread::Tie can benefit from the same optimilizations that may take place here in the future.

Thread::Serializeモジュールは、スレッド間のデータ構造をシリアル化するのに 用いられる諸ルーチンを集中化するためのライブラリである。集中化することに よって、Thread::ConveyorThread::PoolあるいはThread::Tieのような 他のモジュールは、将来これに取って代わる最適化から利益を得ることができる。

サブルーチン

There are only two subroutines.

二つのサブルーチンがあるだけだ。

freeze

 my $frozen = freeze( $scalar );

 my $frozen = freeze( @array );

The "freeze" subroutine takes all the parameters passed to it, freezes them and returns a frozen representation of what was given. The parameters can be scalar values or references to arrays or hashes. Use the thaw subroutine to obtain the original data-structure back.

"freeze"サブルーチンは渡された全てのパラメータをとり、そららを凍結し、その 凍結したものを返す。パラメータはスカラー値か、配列またはハッシュのリファレンス が可能である。元のデータ構造に戻すにはthawサブルーチンを使う。

thaw

 my $scalar = thaw( $frozen );

 my @array = thaw( $frozen );

The "thaw" subroutine returns the data-structure that was frozen with a call to freeze. If called in a scalar context, only the first element of the data-structure that was passed, will be returned. Otherwise the entire data-structure will be returned.

"thaw"サブルーチンはfreezeによって凍結されたデータ構造を返す。 サブルーチンがスカラーコンテキストで呼ばれると、渡されたデータ構造の一番目の 要素だけが返される。それ以外のコンテキストでは完全なデータ構造が返される。

It is up to the developer to make sure that single argument calls to freeze are always matched by scalar context calls to thaw.

一つの引数によるfreezeの呼び出しがスカラーコンテキストでのthawの 呼び出しに対応するよう保証するのは、開発者の責任である。

最適化

To reduce memory and CPU usage, this module uses load. This causes subroutines only to be compiled in a thread when they are actually needed at the expense of more CPU when they need to be compiled. Simple benchmarks however revealed that the overhead of the compiling single routines is not much more (and sometimes a lot less) than the overhead of cloning a Perl interpreter with a lot of subroutines pre-loaded.

メモリとCPUの使用を抑えるために、このモジュールはloadを利用する。 このモジュールの利用により、サブルーチンが実際に必要になるときにだけ、 それらはスレッド内でコンパイルされるのだが、サブルーチンがコンパイル されると、より多くのCPUが犠牲になる。しかし単純なベンチマークにおいて、 一つのルーチンをコンパイルするオーバーヘッドは、あらかじめロードされた 多数のサブルーチンを伴うPerlインタプリタをクローンするオーバーヘッドよりも それほど大きくならない(そして時には大幅に減じる)ことが明らかである。

作者

Elizabeth Mattijsen, <liz@dijkmat.nl>.

Please report bugs to <perlbugs@dijkmat.nl>.

著作権

Copyright (c) 2002-2003 Elizabeth Mattijsen <liz@dijkmat.nl>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

参考

load, Thread::Conveyor, Thread::Pool, Thread::Tie.