[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams

From: John Mastro
Subject: Re: [PATCH] Elpa: Pinpoint semantics of `seq-subseq' for streams
Date: Wed, 14 Sep 2016 17:51:05 -0700

Clément Pit--Claudel <address@hidden> wrote:
>> I think this is actually a very good example why it is good to
>> forbid negative indexes.  If you are interested in the last n lines
>> of a file, why would you dissect the complete file (or buffer) into
>> lines and throw away nearly all of the result?
> Because it's much more memory-efficient, as long as the file's lines
> are short :) Note that I was careful to say file, not buffer: I don't
> need to load a full file in memory before I start processing its
> lines. Same for the output of a running process: if I just want the
> last n lines, then accumulating all of the output before going to the
> end and looking backwards is extremely inefficient, memory-wise.
> Dissecting the output (splitting it on newlines) and using a ring
> buffer to keep only the last `n` ones is much better.

(Asking for my own edification)

Wouldn't finding the last N elements require forcing every thunk in the
stream (to find its end), thus using more memory than a linked list with
the same contents? As long as you don't "hang on to the head" of the
stream, earlier elements could be reclaimed by GC, but the same applies
to a list.

In short, I find this conversation interesting, but don't quite
understand where the memory savings come in :)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]