4章.参照渡しと値渡し (その4)
今回は参照渡しをしてみます。ちょっと本に戻ります。p.57の「4.1.2 dRubyでは?」からです。が、Marshalのあたりは、同じようなことを既に確認したような気がしますのでここでは省略します。本に沿って試してみて下さいませ。ここではその続き「p.58 参照の値渡し」から読みます。
Marshal.loadによって直列化したオブジェクトをMarshal.dumpで復元するということは、つまりオブジェクトの複製を作ることにほかなりません。ではdRubyはいつも値渡しなのでしょうか?
実は当たっているとも言えるし違うとも言えます。 dRubyでの参照渡しは、元のオブジェクトの代わりに参照情報を含むオブジェクトを直列化することで実現されます。つまり、参照渡しは参照オブジェクトの値渡しなのです。逆に、もう一方の値渡しは単純にオブジェクトを直列化するだけです。4.1.2 dRubyでは?
ふむふむ。
Hello, World.の実験で使ったDRbObjectを覚えていますか? DRbObjectは元のオブジェクトを参照する情報をもったオブジェクトです。 DRbObjectには目的にごとに二つの生成方法が用意されています。一つはDRbObject.new_with_uriを使ってURIからリモートオブジェクトへの参照を作ることです。もう一つはDRbObject.new(obj)のようにオブジェクトを与え自プロセスのオブジェクトへの参照を作ることです。
4.1.2 dRubyでは?
ふむふむふむ。
DRbObject.new(obj)によって、任意のオブジェクトへの参照オブジェクトを作ります。参照を作るということは、他のプロセスがこの参照をつかってメソッド呼び出しする可能性があるということです。ですから、オブジェクトへの参照を作る前に、DRb.start_serviceによってdRubyのサーバを自プロセスで起動しておかなくてはなりません。
4.1.2 dRubyでは?
ふむふむふむふむふむ!!(こればっか)
元の文章でも充分わかりやすいですが、整理します。ここ、すごい重要な気がします。
4-1. DRbObject.new_with_uriを使ってURIからリモートオブジェクトへの参照を作る
4-2. DRbObject.new(obj)のようにオブジェクトを与え自プロセスのオブジェクトへの参照を作る
なぜなら、そのオブジェクトを他からリモート呼び出しすることがあるから(オブジェクトの実体はクライアントにあるから)
すげ!ちょっと感動します。
確かめてみます。p.60に掲載されているように、ハッシュを公開するサーバーを用意します。
% irb --prompt simple -r drb/drb
>> front = {}
>> DRb.start_service(nil, front)
=> #
>> DRb.uri
=> "druby://yourhost:1426"
はい立ち上げてみました。
前回の値渡しの復習をかねて、文字列をハッシュ(フロントオブジェクト)に登録してみます。
there = DRbObject.new_with_uri('druby://yourhost:1426')
str = "Hello, World."
there[1] = str
これは勿論うまくいく。では次に参照を渡してみます。参照はDRbObjectのことです。
there = DRbObject.new_with_uri('druby://yourhost:1426')
str = "Hello, World."
there[1] = str
there[2] = DRbObject.new(str)
しかしこれではうまくいきません。もしこのまま実行すると
in `current_server': DRb::DRbServerNotFound (DRb::DRbServerNotFound)
というエラーが出てしまいます。
なぜなら、DRb.start_serviceをしていないからです。クライアントからオブジェクトの参照を放り込んでいるということは実体がクライアントにあるということです。なのでメッセージに応答するのはクライアントです。クライアントが他局からのメッセージ呼び出しを受け付けることができないと駄目なので、dRubyのサービスが必要です。これがDRb.start_serviceをしなければならない理由です。
DRb.start_service
there = DRbObject.new_with_uri('druby://yourhost:1426')
str = "Hello, World."
there[1] = str
there[2] = DRbObject.new(str)
これでうまくいきます。
今日はここまで。次回は今回やった参照渡しの部分をもうちょっと詳しく見るつもりです。
コメント (57)
I’d have to give blessing with you here. Which is not something I usually do! I love reading a post that will make people think. Also, thanks for allowing me to comment!
投稿者: Quintin Solo | 2010年12月13日 17:30
日時: 2010年12月13日 17:30
I like what you guys are up also. Such smart work and reporting! Keep up the excellent works guys I’ve incorporated you guys to my blogroll. I think it'll improve the value of my site :)
投稿者: Latina Schirrmacher | 2011年04月01日 16:16
日時: 2011年04月01日 16:16
I haven’t checked in here for a while because I thought it was getting boring, but the last several posts are good quality so I guess I’ll add you back to my everyday bloglist. You deserve it my friend :)
投稿者: Nam Nimocks | 2011年04月02日 21:37
日時: 2011年04月02日 21:37
I’d be inclined to see eye to eye with you here. Which is not something I usually do! I really like reading a post that will make people think. Also, thanks for allowing me to comment!
投稿者: Odis Jenrette | 2011年05月20日 05:17
日時: 2011年05月20日 05:17
Hey there! I know this is certainly considerably off theme but I was thinking which site platform are you using for this web page? I’m finding tired of Wordpress as I’ve had issues with hackers and I’m hunting at alternatives for another platform. I'd be awesome if you could stage me in the direction of a fantastic platform.
投稿者: handbag gucci | 2011年05月22日 04:07
日時: 2011年05月22日 04:07
I'm extremely impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it’s rare to see a nice blog like this one nowadays..
投稿者: Ignacia Anne | 2011年05月28日 06:46
日時: 2011年05月28日 06:46
obviously like your web-site but you have to check the spelling on several of your posts. Many of them are rife with spelling problems and I find it very bothersome to tell the truth nevertheless I’ll certainly come back again.
投稿者: Georgie Sumerall | 2011年06月01日 22:57
日時: 2011年06月01日 22:57
F*ckin’ tremendous things here. I am very glad to see your post. Thanks a lot and i'm looking forward to contact you. Will you kindly drop me a mail?
投稿者: Azalee Zaltz | 2011年06月12日 04:32
日時: 2011年06月12日 04:32
This is the suitable blog for anyone who desires to seek out out about this topic. You notice so much its nearly exhausting to argue with you (not that I actually would need…HaHa). You undoubtedly put a new spin on a topic thats been written about for years. Great stuff, just nice!
投稿者: Rosanna Contrerras | 2011年07月14日 02:54
日時: 2011年07月14日 02:54
It’s really a nice and helpful piece of information. I am glad that you shared this useful info with us. Please keep us informed like this. Thank you for sharing.
投稿者: Vita Riera | 2011年07月15日 08:36
日時: 2011年07月15日 08:36
It’s onerous to search out educated people on this matter, but you sound like you already know what you’re speaking about! Thanks
投稿者: Lisette Prochak | 2011年07月16日 03:21
日時: 2011年07月16日 03:21
I discovered your weblog website on google and check a number of of your early posts. Continue to keep up the superb operate. I just extra up your RSS feed to my MSN Information Reader. Searching for ahead to studying extra from you in a while!…
投稿者: Refugio Deweese | 2011年07月17日 09:16
日時: 2011年07月17日 09:16
It’s arduous to find knowledgeable people on this matter, but you sound like you already know what you’re talking about! Thanks
投稿者: Cinderella Boscia | 2011年07月30日 04:31
日時: 2011年07月30日 04:31
I’ll right away snatch your rss as I can't find your email subscription hyperlink or e-newsletter service. Do you have any? Kindly permit me recognise so that I may just subscribe. Thanks.
投稿者: newsletter | 2011年08月02日 08:57
日時: 2011年08月02日 08:57
of course like your web site but you have to check the spelling on several of your posts. A number of them are rife with spelling issues and I find it very bothersome to inform the reality however I’ll surely come back again.
投稿者: newsletter templates | 2011年08月11日 16:53
日時: 2011年08月11日 16:53
hello there and thank you in your information – I’ve certainly picked up something new from proper here. I did then again expertise a few technical points the usage of this web site, as I experienced to reload the website lots of instances previous to I may just get it to load properly. I had been puzzling over in case your hosting is OK? No longer that I am complaining, however slow loading cases times will very frequently impact your placement in google and could damage your high quality ranking if advertising and ***********|advertising|advertising|advertising and *********** with Adwords. Anyway I’m including this RSS to my e-mail and can glance out for a lot extra of your respective fascinating content. Make sure you replace this again very soon..
投稿者: newsletter topics | 2011年08月13日 10:09
日時: 2011年08月13日 10:09
Aw, this was a really nice post. In idea I wish to put in writing like this moreover – taking time and actual effort to make a very good article… but what can I say… I procrastinate alot and under no circumstances seem to get one thing done.
投稿者: sample newsletter templates | 2011年08月13日 14:16
日時: 2011年08月13日 14:16
Your place is valueble for me. Thanks!…
投稿者: enewsletter templates | 2011年08月15日 01:27
日時: 2011年08月15日 01:27
I conceive other website proprietors should take this internet site as an model, very clean and excellent user genial design .
投稿者: العاب اكشن | 2011年08月16日 20:39
日時: 2011年08月16日 20:39
I’m definitely bookmarking this site. Actually nice articles. Do you advocate any other readings?
投稿者: rental test equipment | 2011年08月16日 23:49
日時: 2011年08月16日 23:49
Although operating a enterprise sounds cool and all that. But the fact, I believe essential kind a agenda so that you simply don’t get too involved. I favored that stuff you mentioned “existence is stability”. Maybe hiring somebody do your paintings is a brilliant idea.
投稿者: Ross Zeno | 2011年08月17日 18:07
日時: 2011年08月17日 18:07
Hi there, simply changed into alert to your blog thru Google, and found that it is really informative. I am gonna be careful for brussels. I’ll appreciate if you proceed this in future. Many people will likely be benefited out of your writing. Cheers!
投稿者: newsletter template html | 2011年08月18日 17:27
日時: 2011年08月18日 17:27
yes, i consider that these form of suggestions are important. however, that’s just a bit part in web optimization CMIIW.
投稿者: Juliette Serena | 2011年08月25日 19:43
日時: 2011年08月25日 19:43
I’m really loving the contents of your blog. Hopefully you keep posting regularly. Thanks.
投稿者: buy plan b | 2011年08月29日 01:23
日時: 2011年08月29日 01:23
I’m really loving the contents of your blog. Hopefully you keep posting regularly. Thanks.
投稿者: plan b cost | 2011年08月29日 07:46
日時: 2011年08月29日 07:46
I’m really loving the contents of your blog. Hopefully you keep posting regularly. Thanks.
投稿者: plan b prescription | 2011年08月29日 12:10
日時: 2011年08月29日 12:10
Attempt to strive, that's the key to good fortune, giving up shouldn’t be incorporated on our dictionary (i believe).
投稿者: internet marketing | 2011年08月29日 18:54
日時: 2011年08月29日 18:54
That is the correct blog for anyone who wants to find out about this topic. You understand so much its virtually exhausting to argue with you (not that I really would need…HaHa). You undoubtedly put a new spin on a topic thats been written about for years. Great stuff, simply great!
投稿者: Polly Pescador | 2011年09月02日 18:15
日時: 2011年09月02日 18:15
I usually don’t put up in Blogs but your blog compelled me to, amazing work.. beautiful …
投稿者: Kip Hilscher | 2011年09月07日 09:38
日時: 2011年09月07日 09:38
I believe, to be an excellent affiliate marketer is the hardest thing to do as a blogger, you should have enormous site visitors to get the attainable purchaser and in addition must to build your own viewers, end result honestly i’ve never made a single sale with my first weblog
投稿者: Kaleigh Takaoka | 2011年09月12日 07:20
日時: 2011年09月12日 07:20
It’s onerous to search out educated people on this topic, however you sound like you recognize what you’re speaking about! Thanks
投稿者: Claud Cangelosi | 2011年09月17日 03:57
日時: 2011年09月17日 03:57
ohh…nice submit however actually?/? :P
投稿者: outboard covers | 2011年09月22日 08:26
日時: 2011年09月22日 08:26
It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks
投稿者: may phat dien | 2011年09月25日 20:58
日時: 2011年09月25日 20:58
Aw, this was a really nice post. In thought I would like to put in writing like this moreover – taking time and precise effort to make a very good article… however what can I say… I procrastinate alot and not at all seem to get something done.
投稿者: footjob board | 2011年10月01日 00:41
日時: 2011年10月01日 00:41
you have a great blog here! would you like to make some invite posts on my blog?
投稿者: cho thue may phat dien | 2011年10月04日 19:04
日時: 2011年10月04日 19:04
I just wanted to type a note in order to say thanks to you for those amazing tricks you are posting on this site. My incredibly long internet investigation has at the end been recognized with pleasant facts and techniques to share with my friends and classmates. I would assert that we visitors actually are undoubtedly lucky to be in a magnificent community with many marvellous professionals with very beneficial opinions. I feel very much fortunate to have come across your entire web page and look forward to plenty of more awesome times reading here. Thanks a lot again for all the details.
投稿者: Dorian Steinborn | 2011年10月06日 04:32
日時: 2011年10月06日 04:32
Aw, this was a very nice post. In thought I wish to put in writing like this additionally – taking time and actual effort to make an excellent article… however what can I say… I procrastinate alot and by no means seem to get something done.
投稿者: Marty Accomando | 2011年10月06日 10:23
日時: 2011年10月06日 10:23
:O So mush Info :O … THis Is he MOst AMAzing SIte DUDe… :D
投稿者: Magali Beeck | 2011年10月06日 13:07
日時: 2011年10月06日 13:07
This is a very good tips especially to those new to blogosphere, brief and accurate information… Thanks for sharing this one. A must read article.
投稿者: Raymond Pettiway | 2011年10月07日 06:01
日時: 2011年10月07日 06:01
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
投稿者: Sherrill Labarge | 2011年10月07日 14:43
日時: 2011年10月07日 14:43
You made some respectable points there. I looked on the web for the issue and located most individuals will go together with with your website.
投稿者: Cecile Kraynak | 2011年10月09日 05:05
日時: 2011年10月09日 05:05
It’s onerous to find educated folks on this topic, however you sound like you understand what you’re speaking about! Thanks
投稿者: Sherri Kelleher | 2011年10月15日 17:00
日時: 2011年10月15日 17:00
Hi there, just became alert to your blog through Google, and found that it's truly informative. I am gonna watch out for brussels. I’ll be grateful if you continue this in future. A lot of people will be benefited from your writing. Cheers!
投稿者: Travel Mysore | 2011年10月18日 00:08
日時: 2011年10月18日 00:08
I’m not that much of a online reader to be honest but your sites really nice, keep it up! I'll go ahead and bookmark your website to come back down the road. Many thanks
投稿者: threesomes solo girl | 2011年10月18日 11:56
日時: 2011年10月18日 11:56
yes, i believe that those type of ideas are important. nonetheless, that’s just a bit half in web optimization CMIIW.
投稿者: Wendi Culbertson | 2011年10月21日 10:10
日時: 2011年10月21日 10:10
We're in powerful instances these days, financial is pretty bad. To gain visitors and readers, it’s really about putting high quality contents and fascinating articles.
投稿者: Arnoldo Derienzo | 2011年10月24日 00:20
日時: 2011年10月24日 00:20
This is a nice article. I've now left the rat race, never to seem back. You’re right that the one technique to make any first rate cash is by way of operating your individual enterprise!
投稿者: Ted Golbin | 2011年10月27日 03:01
日時: 2011年10月27日 03:01
I’m sure this may be amazingly helpful for the ones weblog via - all of those seem like pretty excellent ideas for approach spend a while together with your site.
投稿者: Myron Hounchell | 2011年10月27日 08:46
日時: 2011年10月27日 08:46
I’d must examine with you here. Which isn't something I often do! I get pleasure from studying a put up that may make people think. Additionally, thanks for allowing me to remark!
投稿者: Dick Elian | 2011年10月29日 19:59
日時: 2011年10月29日 19:59
攻めようにも勝手に進んでればやりようがないの。一応第三者機関の検査が基礎工事で1回入ってるはずなので それだけが頼りのような???
投稿者: burberry scarf sale | 2011年11月02日 06:33
日時: 2011年11月02日 06:33
I just want to tell you that I'm newbie to blogging and really enjoyed this web site. Probably I’m want to bookmark your blog . You really have wonderful article content. Cheers for revealing your webpage.
投稿者: Milan Toniatti | 2011年11月15日 09:16
日時: 2011年11月15日 09:16
I simply want to tell you that I am very new to blogs and definitely loved this web site. Likely I’m planning to bookmark your blog . You surely have beneficial articles and reviews. With thanks for revealing your blog site.
投稿者: Emmett Adrien | 2011年11月16日 02:06
日時: 2011年11月16日 02:06
gr8 resrch bro…
投稿者: Aide Howton | 2011年11月16日 09:59
日時: 2011年11月16日 09:59
I’m undoubtedly bookmarking this site. Really great articles. Do you recommend another readings?
投稿者: Sheryl Ikeda | 2011年11月20日 12:42
日時: 2011年11月20日 12:42
one of the best idea is 100% content. Use content material when you do your promotions. You’ve most likely seen in this weblog at any time when I do a weblog publish that just about simply recommends a services or products, all the time a few people don’t like that.
投稿者: clairvoyant psychic readings | 2011年11月22日 10:57
日時: 2011年11月22日 10:57
I’d must examine with you here. Which isn't one thing I normally do! I take pleasure in studying a post that will make people think. Additionally, thanks for allowing me to remark!
投稿者: Ivory Kerry | 2011年12月01日 00:45
日時: 2011年12月01日 00:45
OMG, I’ve been seeking for this material all over the internet. thanks
投稿者: fahren | 2011年12月26日 14:05
日時: 2011年12月26日 14:05