[erlang-questions] simple question about list memory consumption
Sun Jul 8 21:41:14 CEST 2012
About the two lists you were speaking about (I suppose you were referring
to the output of lists:map/2 and lists:seq/2), the second is destroyed as
soon as lists:map/2 exits. So, there shouldn't be any overhead here. And,
yes, the memory consumption peaked at higher value, but stabilized itself
at the value I mentioned before.
On a 64-bits machine, 2 words = 16 B and 3 words = 24 B, so, my value of 21
B is exactly in between 2 and 3 words. I suppose you worked on 32-bits
machine or with half-world emulator and you got half of that value (or a
bit less if we are to consider that the shell is adding bigger overhead).
On Sun, Jul 8, 2012 at 7:22 AM, <> wrote:
> > Hm, ignore my previous answer, then; I was under the impression that
> > small enough integers would be stored as immediates in the
> > list cell...
> They are.
> See the Efficiency guide.
> "String ... 2 words per character"
> Each list cell holds one integer, which *is* an immediate in the
> list cell and points nowhere else, and one pointer to the next
> element in the list.
> >> 2. opening an Erlang shell (few MB consumption - stable);
> >> 3. executing:
> >> L = lists:map(fun(_) -> 107 end,lists:seq(1,10000000)), ok.
> Two things strike me about this.
> (A) you construct TWO lists here, so at 8 bytes per list cell
> on a 32-bit machine, there's 16 bytes each already.
> (B) You are doing this in the shell, where expressions are
> interpreted. I have no idea what space overheads that adds.
> Is there a way of measuring the amount of heap space currently
> _used_ in a process? process_info>heap_size and
> process_info>total_heap_size seem to be about the amount of
> space allocated for a process, including its stack and any quantity
> of free space. So the following only gave me an approximate idea:
> heap_size() ->
> element(2, process_info(self(), heap_size)).
> ss(N) ->
> Before = heap_size(),
> Result = loop(N),
> After = heap_size(),
> (After-Before)*1.0 / length(Result).
> loop(0) ->
> loop(N) ->
> [$k | loop(N-1)].
> However, the idea it _did_ give me was "between 2 and 3 words
> per character", so it looks like "2 words per character" as
> stated in the Efficiency Guide is, after all, true.
> It's certainly nowhere near 21 bytes.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions