Re: [go-nuts] Ensuring Alignment with unsafe.Pointer

2025-06-11 Thread 'Axel Wagner' via golang-nuts
I'm far from an expert on the runtime. But I believe one condition under which this breaks is if `T` contains pointers (including pointer-like types, e.g. `string`, `map`, `[]T`…). The GC needs to know which memory contains pointers. If `T` is e.g. `*int` You are spreading a pointer over [N]byte (w

Re: [go-nuts] Ensuring Alignment with unsafe.Pointer

2025-06-11 Thread Timur Celik
Sorry, I think the code needs more explanation: A value of type Aligned[T,A] will allocate enough memory to contain one instance of T with alignment A. The fields pad and val will contain only garbage, they only exist for allocating enough memory and could as well be a byte array. To get the al

Re: [go-nuts] Ensuring Alignment with unsafe.Pointer

2025-06-11 Thread Mikk Margus
Oh, yeah, you're right, that does seem to be the intent. From what I know, and based on the documentation I linked before[1], you can, at most, get 32-bit alignment on 32-bit platforms and 64-bit alignment on 64-bit platforms with Go. At least with this approach. For in-memory size/alignment pu

Re: [go-nuts] Ensuring Alignment with unsafe.Pointer

2025-06-11 Thread Robert Engels
I don’t think the code works at all - at least not from an alignment perspective. For instance, assume T is one byte, and you use align 64, it is aligned on 65 byte boundaries. (This may not be fully correct need to read spec on structure member alignment - but the gist should be true) On Jun 10, 2