[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

String copy-on-write question

Lars Christensen

5/5/2008 3:37:00 PM

Hello group,

Ruby implements copy-on-write for strings, so you can do stuff like
this very cheaply:

str = 0.chr * (2**24) # 16MiB allocated
str[100..-1] # this costs only a small amount of memory

How come this optimization does not apply in this case?:

str[100..-2] # this costs around 16MiB bytes of memory

As a side effect, if using regexps on a large string, the pre-match
and post-match variables behave differently:

s = 0.chr * (2**23) + "Hello" + 0.chr * (2**23) # About 16MiB
allocated (after GC)
s.scan(/Hello/) { |m| p m } # This is free
p $'.size # This is free
p $`.size # This costs another 8MiB.

Any insights?

Lars
12 Answers

Rudy Canoza

3/27/2008 8:59:00 PM

0

Goo - Fuckwit David Harrison, THE GOOBER, a colossally
stupid fuckwit and a credulous believer - lied and
presented no challenge:
> On Mon, 24 Mar 2008 17:58:48 GMT, "Lee" <nobody@127.0.0.1> wrote:
>
>> Goo - Fuckwit David Harrison, THE GOOBER, a colossally stupid fuckwit and a credulous believer - lied and presented no challenge:
>>> The beliefs and behaviors of atheists are often
>>> quite amusing. There are several types of atheists.
>>> I'm aware of two, and expect there probably are
>>> members of a third group but I have yet to encounter
>>> more than one, if any.
>>>
>>> A.
>>> Weak Atheists - don't have a true belief either way
>>> whether a creator exists or not. I am a weak atheist
>>> of what appears to be a very unique type since I
>>> openly consider the possibility that a creator does
>>> exist, more than the possibility that he does not.
>>>
>>> B.
>>> Strong Atheists ashamed of their faith - one of the
>>> more amusing things I learned is that people who
>>> ONLY give the indication that they *disbelieve* in
>>> a creator, are also ashamed to admit their faith
>>> in that being the correct possibility. I feel that I've
>>> met a number of people who ARE strong atheists,
>>> yet amusingly they are not willing to admit it.
>>>
>>> C.
>>> Strong Atheists not ashamed of their faith - as yet
>>> that is still just a concept for me, since so far I
>>> haven't encountered more than one--if any--strong
>>> atheists who are willing to admit their own faith.
>>>
>>> Weak atheists such as myself must consider
>>> the possibility of a creator more than the possibility
>>> that he doesn't exist, because there is much more
>>> to consider since if a creator does not exist that's
>>> as far as you can ever go in that direction, while if
>>> a creator does there is no limit. People who claim
>>> to be weak atheists but don't consider the possibility
>>> of a creator, are fooling themselves.
>>>
>>> There are a good number of people who give
>>> every indication that they are strong atheists
>>> except for one: That they deny it. Why? It's part
>>> of the amusement, but it's also pathetic. Recently
>>> we've seen from other threads that none of the
>>> supposed atheists in several ngs are willing to admit
>>> their faith. So what to think? They ridicule others
>>> for considering the possibility of a creator, yet they
>>> are also unwilling to admit their own faith that a
>>> creator does not exist. It goes beyond that to the
>>> point that such people are ashamed to admit their
>>> faith in anything. That has been tested in several
>>> ngs, and found to be true. Not only are strong
>>> atheists ashamed of their own faith, but amusingly
>>> it seems that some of them even consider themselves
>>> to "free thinkers". It is hilarious that people who have
>>> taken their mental refuge in that one extremely limiting
>>> possibility, also consider themselves to be free thinkers!
>>>
>> What catagory is it when you ROFL
>
> Do you have faith that a creator does not exist?

Stupid, typical Fuckwit question.

You really suck at this, Fuckwit; you're just awful.

Lord Vetinari

3/28/2008 5:06:00 PM

0

<dh@.> wrote in message news:j8bou3her0f6n29vrfogbte9qe0llkfgio@4ax.com...
[snip]
> Do you have faith that a creator does not exist?
> If so, are you willing to admit it? Do you think other
> people should, or should not?

Amazing, isn't it? Referring, of course, to these cretins with low IQs who
cannot recognize their position, intellectually & educationally speaking.

So, why don't you just give it up, cretin? We can clearly see the strings
that control you, you know.


dh

3/31/2008 5:26:00 AM

0

On Fri, 28 Mar 2008 12:06:09 -0500, "Lord Vetinari" <vetinari@ameritech.net> wrote:

><dh@.> wrote in message news:j8bou3her0f6n29vrfogbte9qe0llkfgio@4ax.com...
>[snip]
>> Do you have faith that a creator does not exist?
>> If so, are you willing to admit it? Do you think other
>> people should, or should not?
>
>Amazing, isn't it? Referring, of course, to these cretins with low IQs who
>cannot recognize their position

There are idiots who refuse to admit their OBVIOUS faith in the
possibility that a creator does not exist. The question your point
immediately brings to mind is whether they are really too stupid to
understand, or they are lying deliberately trying to make people
believe they honestly are that stupid.

Free Lunch

3/31/2008 11:48:00 PM

0

On Mon, 31 Mar 2008 14:26:14 +0900, in alt.atheism
dh@. wrote in <6ft0v3dnv51tgr2nu4kn7k2f5plj1scjq4@4ax.com>:
>On Fri, 28 Mar 2008 12:06:09 -0500, "Lord Vetinari" <vetinari@ameritech.net> wrote:
>
>><dh@.> wrote in message news:j8bou3her0f6n29vrfogbte9qe0llkfgio@4ax.com...
>>[snip]
>>> Do you have faith that a creator does not exist?
>>> If so, are you willing to admit it? Do you think other
>>> people should, or should not?
>>
>>Amazing, isn't it? Referring, of course, to these cretins with low IQs who
>>cannot recognize their position
>
> There are idiots who refuse to admit their OBVIOUS faith in the
>possibility that a creator does not exist. The question your point
>immediately brings to mind is whether they are really too stupid to
>understand, or they are lying deliberately trying to make people
>believe they honestly are that stupid.

Keep saying whatever you like. It won't be true, but you don't care
whether you are honest, do you.

Lady Azure, Baroness of the North Pole

4/1/2008 5:09:00 AM

0

Free Lunch wrote:
>
> On Mon, 31 Mar 2008 14:26:14 +0900, in alt.atheism
> dh@. wrote in <6ft0v3dnv51tgr2nu4kn7k2f5plj1scjq4@4ax.com>:
> >On Fri, 28 Mar 2008 12:06:09 -0500, "Lord Vetinari" <vetinari@ameritech.net> wrote:
> >
> >><dh@.> wrote in message news:j8bou3her0f6n29vrfogbte9qe0llkfgio@4ax.com...
> >>[snip]
> >>> Do you have faith that a creator does not exist?
> >>> If so, are you willing to admit it? Do you think other
> >>> people should, or should not?
> >>
> >>Amazing, isn't it? Referring, of course, to these cretins with low IQs who
> >>cannot recognize their position
> >
> > There are idiots who refuse to admit their OBVIOUS faith in the
> >possibility that a creator does not exist. The question your point
> >immediately brings to mind is whether they are really too stupid to
> >understand, or they are lying deliberately trying to make people
> >believe they honestly are that stupid.
>
> Keep saying whatever you like. It won't be true, but you don't care
> whether you are honest, do you.

No, they are engaging in a Major Flame War trying to prove to the Beast
why he is a Liar.
Started on Angels, when I caught the Sassers.
Hacker Pricks!!!!!!!!!
So they sicked their "Gang" on me.
Been a Growing Cross Posted Flame War ever since.
Won't stop, because the Governments are "Assisting" the "Hackers"!
You like spam and Viruses don't you.
Your not a Corporation so we can beta test our programs on your systems.
Won't hurt anyone that way.
Who cares of Grandma can't get back on line.
Let her take a course in Computer Programming.

dh

4/2/2008 5:55:00 AM

0

On Mon, 31 Mar 2008 23:48:27 GMT, Free Lunch <lunch@nofreelunch.us> wrote:

>On Mon, 31 Mar 2008 14:26:14 +0900, in alt.atheism
>dh@. wrote in <6ft0v3dnv51tgr2nu4kn7k2f5plj1scjq4@4ax.com>:
>>On Fri, 28 Mar 2008 12:06:09 -0500, "Lord Vetinari" <vetinari@ameritech.net> wrote:
>>
>>><dh@.> wrote in message news:j8bou3her0f6n29vrfogbte9qe0llkfgio@4ax.com...
>>>[snip]
>>>> Do you have faith that a creator does not exist?
>>>> If so, are you willing to admit it? Do you think other
>>>> people should, or should not?
>>>
>>>Amazing, isn't it? Referring, of course, to these cretins with low IQs who
>>>cannot recognize their position
>>
>> There are idiots who refuse to admit their OBVIOUS faith in the
>>possibility that a creator does not exist. The question your point
>>immediately brings to mind is whether they are really too stupid to
>>understand, or they are lying deliberately trying to make people
>>believe they honestly are that stupid.
>
>Keep saying whatever you like. It won't be true,

I only say it because it is true and it's something I consider to
be significant.

>but you don't care whether you are honest, do you.

Yes I do, and I wonder how honest other people are being
especially when it's hard to believe that they could be.

dh

4/2/2008 5:56:00 AM

0

On Mon, 31 Mar 2008 21:09:10 -0800, Azure <laddie'o'lugh@gall's.org> wrote:

>Free Lunch wrote:
>>
>> On Mon, 31 Mar 2008 14:26:14 +0900, in alt.atheism
>> dh@. wrote in <6ft0v3dnv51tgr2nu4kn7k2f5plj1scjq4@4ax.com>:
>> >On Fri, 28 Mar 2008 12:06:09 -0500, "Lord Vetinari" <vetinari@ameritech.net> wrote:
>> >
>> >><dh@.> wrote in message news:j8bou3her0f6n29vrfogbte9qe0llkfgio@4ax.com...
>> >>[snip]
>> >>> Do you have faith that a creator does not exist?
>> >>> If so, are you willing to admit it? Do you think other
>> >>> people should, or should not?
>> >>
>> >>Amazing, isn't it? Referring, of course, to these cretins with low IQs who
>> >>cannot recognize their position
>> >
>> > There are idiots who refuse to admit their OBVIOUS faith in the
>> >possibility that a creator does not exist. The question your point
>> >immediately brings to mind is whether they are really too stupid to
>> >understand, or they are lying deliberately trying to make people
>> >believe they honestly are that stupid.
>>
>> Keep saying whatever you like. It won't be true, but you don't care
>> whether you are honest, do you.
>
>No, they are engaging in a Major Flame War trying to prove to the Beast
>why he is a Liar.

If the Beast does exist he obviously got Howard to lie for him
in his Satanic Bible. That much couldn't be any more obvious.

Hatter

4/10/2008 7:37:00 PM

0

On Apr 2, 1:55 am, dh@. wrote:
> On Mon, 31 Mar 2008 23:48:27 GMT, Free Lunch <lu...@nofreelunch.us> wrote:
> >On Mon, 31 Mar 2008 14:26:14 +0900, in alt.atheism
> >dh@. wrote in <6ft0v3dnv51tgr2nu4kn7k2f5plj1sc...@4ax.com>:
> >>On Fri, 28 Mar 2008 12:06:09 -0500, "Lord Vetinari" <vetin...@ameritech.net> wrote:
>
> >>><dh@.> wrote in messagenews:j8bou3her0f6n29vrfogbte9qe0llkfgio@4ax.com....
> >>>[snip]
> >>>>    Do you have faith that a creator does not exist?
> >>>> If so, are you willing to admit it? Do you think other
> >>>> people should, or should not?
>
> >>>Amazing, isn't it?  Referring, of course, to these cretins with low IQs who
> >>>cannot recognize their position
>
> >>    There are idiots who refuse to admit their OBVIOUS faith in the
> >>possibility that a creator does not exist. The question your point
> >>immediately brings to mind is whether they are really too stupid to
> >>understand, or they are lying deliberately trying to make people
> >>believe they honestly are that stupid.
>
> >Keep saying whatever you like. It won't be true,
>
>     I only say it because it is true and it's something I consider to
> be significant.
>
> >but you don't care whether you are honest, do you.
>
>     Yes I do

well theres a lie right there.

Welcome to the duke club.

Hatter

ts

5/5/2008 4:07:00 PM

0

Lars Christensen wrote:

Well, it's best if you look at rb_str_substr() in string.c

> str[100..-1] # this costs only a small amount of memory

ruby just need to adjust the pointer and the length in the new
object

> str[100..-2] # this costs around 16MiB bytes of memory

one character is missing from the previous string, if it do the
same thing than previously then it must
* adjust the pointer
* adjust the length
* add \0 at the end

This mean that fatally it has modified the string, this is why it
duplicate.

> p $'.size # This is free
> p $`.size # This costs another 8MiB.

same reason here.


Guy Decoux

Robert Klemme

5/5/2008 4:16:00 PM

0

On 05.05.2008 18:07, ts wrote:
> Lars Christensen wrote:
>
> Well, it's best if you look at rb_str_substr() in string.c
>
>> str[100..-1] # this costs only a small amount of memory
>
> ruby just need to adjust the pointer and the length in the new
> object
>
>> str[100..-2] # this costs around 16MiB bytes of memory
>
> one character is missing from the previous string, if it do the
> same thing than previously then it must
> * adjust the pointer
> * adjust the length
> * add \0 at the end
>
> This mean that fatally it has modified the string, this is why it
> duplicate.
>
>> p $'.size # This is free
>> p $`.size # This costs another 8MiB.
>
> same reason here.

Interesting. Do you also happen to know why not an additional field is
used that stores the length? Is the reason maybe usage of C library
string functions that work on zero terminated strings?

Cheers

robert