From: "Ara.T.Howard" Date: 2005-09-08T23:10:19+09:00 Subject: Re: sharing memory in ruby On Thu, 8 Sep 2005, Masahiro TANAKA wrote: > Hi, > >> Ara wrote: >> + ary->ref = Qfalse; >> >> the 'ary->ref' means it will not be free'd... > > This is not what I have intended. > 'ary->ref' is an object that is referred from NArray object > so that the original String object is not garbage-collected. > So here should be `ary->ref = str;'. hmmm. i did not understand that. i'll make the mod and report back... thanks for the insight. >> + ary->ptr = RSTRING(str)->ptr; > > This has a serious caveat. > > s = "0000" > na = NArray.str(s,2,NArray::SINT) > s << "1"*100 # The memory of 's' will be reallocated. > puts na[0] # accesses an invalid memory. yes i'm aware of that. but, in my case, the string is actually a memory map using guy's mmap and i hold it as a private variable. true, it could be changed, but in fact it never is since the map is pinned to a specific region/length of memory and i never tough the mmap object. i think the danger is worth it since programs which normally could not even run run easily and can be written in only a few lines. so, in my case the alternative has a serious caveat - namely NoMemoryError ;-) it __is__ important to realize this danger however. > However, I think it would be quite useful if Ruby have something like a > common memory framework, which Ara suggested, for handling huge memory. any thoughts on what the ruby would look like? kind regards. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================