From: OGASAWARA, T. <t-...@ea...> - 2002-11-28 17:37:30
|
小笠原です。 At Fri, 29 Nov 2002 01:45:25 +0900, Masao Mutoh wrote: > > むとうです。 > > > # というよりこのcopy自体どういう時に使われるものなのでしょう…?(^^; > > GBoxedなオブジェクトの場合、コピーはBOXED2RVAL,GLib::Boxed#initialize, > GVAL2RVALの際に使われます。 > > 例えばBOXED2RVALを使う時に、引数の構造体がどこかしらでmallocされていない > (例えば呼び出し元で宣言したローカル変数など)を渡すだけだと > メモリ周りのバグとなるのですが、copy内部で新しい領域を確保することで > そのようなことの起きないようになっています。 > が、そもそもmallocをGBoxedなオブジェクトが提供する関数群が行っている > のであれば特にコピーする必要はないです。 > #逆に、mallocする必要があるところだけ呼び出し元でmallocすれば良いと > #思います。 なるほど。 > で、このGtkClipboardの場合、そもそもGtkClipboard構造体自体が公開されて > いないし、メモリの確保(copy)、free関数が提供されていないところを見ると > 通常のGTK+アプリケーションから使用する場合もメモリ領域関係を意識する > 必要はない(できない)ということだと思います。 > そこで、小笠原さんが実装されているようにcopy()なんだけど実体はポインタを > そのまま渡しているだけ、で良いと思います。 わかりました。 確かにgtkclipboard.cを見ると、一度確保されたクリップボードは解放されない、 と書いてあるし、同じ種類のクリップボードのオブジェクトは一つしか生成され ないようなので、ポインタをコピーするだけでいいわけですね。 > #まぁ、実際実装してみて動けば良いのかと(^^;)。 動作は問題ないようです。 > > ファイルを添付しておきますので、チェックおねがいします。 > > rbgtktextattributes.cのコメント部分が > rbgtktexttagtable.cになってます。 しまった。(^^; > rbgtkclipboardのwait_is_text_availableはwait_is_text_available?かな。 おっと、そうでした。 以上二点修正して commit しておきました。 それでは。 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 小笠原 健 OGASAWARA, Takeshi t-...@ea... |