> Slices and 'sub-arrays' aren't copies of the objects, they simply refer
> to the identical objects.
The same can be said of any array; the objects inside it exist (in
many cases, at least) already. Still, container objects do take up
memory.
Ruby arrays are copy-on-write though. So subarray = my_array[100...1000100]
does *not* take up any memory except for the additional array object (which
will contain a pointer to the 100th item of my_array and the length 1000000).
ruby -e 'a = [:a,:b,:c]; b = ; while true; b << a[0,3]; end'
That's a little bit unfair though. If you pushed an infinite number of
object of whatever class, you'd eventually run out of memory.
I'm just making the point that even though two arrays may contain the
same objects (not copies), arrays are not cost-free, so creating
intermediate arrays may well be an issue.
I personally find #first() rather confusing (BTW [1,2,3].first
(3).class => Array).
Yes, that's right -- I've over-enumeratored my response
Slices and 'sub-arrays' aren't copies of the objects, they simply refer
to the identical objects.
The same can be said of any array; the objects inside it exist (in
many cases, at least) already. Still, container objects do take up
memory.
Ruby arrays are copy-on-write though. So subarray = my_array[100...1000100]
does *not* take up any memory except for the additional array object (which
will contain a pointer to the 100th item of my_array and the length 1000000).
My memory-eating example was probably unrealistic. Maybe I'm too
steeped in the idea that enumerators are good because they don't
create intermediate arrays.... (I have some real issues with some of
what they do, so I tend to cling to that one.)
Ryan's point (it's not a problem until it's a problem) is a key one,
in any case. I definitely would not discourage creation of
intermediate objects unless there's a real reason to avoid them.
Would you please stop top posting? It's just bad manners.
What makes it bad manners? I'm simply posting where my cursor appears.
That's the point. It's not where the reader's eyes appear. What is
easier to move: Your cursor or some dozens of pairs of eyes?
Agreed. It also makes it that much more difficult to get context. While this is an extreme example, notice how naturally that reads, to someone coming late to the discussion?
It's also a bit irritating how you're spamming your blog (and "learn rails") in something like a signature -- but there's nothing separating it from your post, and it's also right there before whatever you're quoting.
···
Am Donnerstag, 12. Feb 2009, 00:29:38 +0900 schrieb Julian Leviston:
It's not possible to bottom post while maintaining my signatures on the
iPhone as far as I can tell. Sorry.
It's not possible for - drum roll - you! Make a decision what
should be made easy: writing for you or reading for the people you
like to impress. I case you decide making it easier for yourself,
wait for the audience you comb out by that.
It's not possible to bottom post while maintaining my signatures on the
iPhone as far as I can tell. Sorry.
It's not possible for - drum roll - you! Make a decision what
should be made easy: writing for you or reading for the people you
like to impress. I case you decide making it easier for yourself,
wait for the audience you comb out by that.
It's not possible to bottom post while maintaining my signatures on the
iPhone as far as I can tell. Sorry.
It's not possible for - drum roll - you! Make a decision what
should be made easy: writing for you or reading for the people you
like to impress. I case you decide making it easier for yourself,
wait for the audience you comb out by that.
Doesn't the quoting line indicate enough who wrote what?
I find your english unintelligible.
Sorry, I didn't guess how difficult it is for you to accept such a
simple thing. I won't try to argue any further.