代码之家  ›  专栏  ›  技术社区  ›  Chai T. Rex

如何在内存中将ByteArray的数组有效负载与GHC Haskell对齐

  •  2
  • Chai T. Rex  · 技术社区  · 6 年前

    我有几个关于如何对齐的问题 ByteArray# 但是 阵列有效载荷 就在之前

    If you have a value of type ByteArray# , it definitely points to a heap object with type ARR_WORDS (see below)…

    ⋮

    ARR_WORDS , MUT_ARR_PTRS_CLEAN , MUT_ARR_PTRS_DIRTY , MUT_ARR_PTRS_FROZEN0 , MUT_ARR_PTRS_FROZEN

    Non-pointer arrays are straightforward:

    | Header | Bytes | Array payload |

    • newAlignedPinnedByteArray#
    • 假设没有,元数据占用的字节数可能会随着新的GHC版本而改变。如何确定在模块的compiletime中占用的字节数(我非常乐意使用Template Haskell或某种诡计)?
    • 我怎样才能利用这些信息来计算出我应该使数组变得多大以适应填充以获得数组有效负载的对齐?
    • Addr# 到数组有效载荷的填充开始?

    1 回复  |  直到 6 年前
        1
  •  3
  •   K. A. Buhr    6 年前

    从中的GHC源代码 PrimOps.cmm 进行校准的位置:

    /* Now we need to move p forward so that the payload is aligned
       to <alignment> bytes. Note that we are assuming that
       <alignment> is a power of 2, which is technically not guaranteed */
    p = p + ((-p - SIZEOF_StgArrBytes) & (alignment - 1));
    

    所以,它是 是对齐的,不是标题。