Opened 21 months ago

Last modified 10 months ago

#8627 new bug

mallocForeignPtrBytes documentation unobvious regarding memory alignment

Reported by: schernichkin Owned by: ekmett
Priority: normal Milestone:
Component: Core Libraries Version: 7.6.3
Keywords: Cc: core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Documentation bug Test Case:
Blocked By: Blocking:
Related Tickets: #9806 Differential Revisions:

Description

According to the current documentation:

mallocForeignPtr - is equivalent to do { p <- malloc; newForeignPtr finalizerFree p }. It's ok since we can read that the "block of memory is sufficiently aligned" if the mallocBytes function descriprion and newAlignedPinnedByteArray in the function implementation.

mallocForeignPtrBytes - "similar to mallocForeignPtr" but will it alloc aligned memory? Internally it uses newPinnedByteArray which implies memory will not be aligned, but does it really makes any sense?

Plz correct documentation to make it more obvious.

Change History (4)

comment:1 Changed 10 months ago by thomie

  • Cc core-libraries-committee@… added
  • Component changed from Documentation to Core Libraries
  • Owner set to ekmett
  • Type of failure changed from None/Unknown to Documentation bug

comment:2 Changed 10 months ago by ekmett

mallocForeignPtrBytes provides no alignment guarantees. You should in theory need to pad your request by (alignment - 1) bytes and align the resulting memory by hand.

We're missing a mallocForeignPtrBytesAligned, which would behave like allocaBytesAligned which probably should become a separate issue.

comment:3 Changed 10 months ago by ekmett

comment:4 Changed 10 months ago by ekmett

Leaving this ticket open to address the documentation issue.

I've opened #9806 to address potential library changes though.

Note: See TracTickets for help on using tickets.