Can't make sense of newArray# docs

Max Bolingbroke batterseapower at hotmail.com
Tue Jan 18 23:53:09 CET 2011


On 18 January 2011 22:18, Johan Tibell <johan.tibell at gmail.com> wrote:
> Why is the size in bytes?

I think the docs are wrong. The code for newArray# (in PrimOps.cmm)
interprets n as a size in words:

{{{
stg_newArrayzh
{
    W_ words, n, init, arr, p, size;
    /* Args: R1 = words, R2 = initialisation value */

    n = R1;
    MAYBE_GC(R2_PTR,stg_newArrayzh);

    // the mark area contains one byte for each 2^MUT_ARR_PTRS_CARD_BITS words
    // in the array, making sure we round up, and then rounding up to a whole
    // number of words.
    size = n + mutArrPtrsCardWords(n);
    words = BYTES_TO_WDS(SIZEOF_StgMutArrPtrs) + size;
    ("ptr" arr) = foreign "C" allocate(MyCapability() "ptr",words) [R2];
    TICK_ALLOC_PRIM(SIZEOF_StgMutArrPtrs, WDS(n), 0);

    ...
}
}}}

Cheers,
Max



More information about the Glasgow-haskell-users mailing list