github.com/benz9527/toy-box/algo@v0.0.0-20240221120937-66c0c6bd5abd/list/node_element_test.go (about)

     1  package list
     2  
     3  import (
     4  	"testing"
     5  	"unsafe"
     6  )
     7  
     8  func TestNodeElementMemoryAlignment(t *testing.T) {
     9  	ne1 := NewNodeElement[int](1)
    10  	t.Logf("ne1 ptr alignment: %d", unsafe.Alignof(ne1))
    11  	t.Logf("ne1 next ptr alignment: %d", unsafe.Alignof(ne1.(*nodeElement[int]).next))
    12  	t.Logf("ne1 prev ptr alignment: %d", unsafe.Alignof(ne1.(*nodeElement[int]).prev))
    13  	t.Logf("ne1 list ptr alignment: %d", unsafe.Alignof(ne1.(*nodeElement[int]).list))
    14  	t.Logf("ne1 lock ptr alignment: %d", unsafe.Alignof(ne1.(*nodeElement[int]).lock))
    15  	t.Logf("ne1 value alignment: %d", unsafe.Alignof(ne1.(*nodeElement[int]).value))
    16  	t.Logf("ne1 ptr sizeof: %d", unsafe.Sizeof(ne1))
    17  	t.Logf("ne1 next ptr sizeof: %d", unsafe.Sizeof(ne1.(*nodeElement[int]).next))
    18  	t.Logf("ne1 prev ptr sizeof: %d", unsafe.Sizeof(ne1.(*nodeElement[int]).prev))
    19  	t.Logf("ne1 list ptr sizeof: %d", unsafe.Sizeof(ne1.(*nodeElement[int]).list))
    20  	t.Logf("ne1 lock ptr sizeof: %d", unsafe.Sizeof(ne1.(*nodeElement[int]).lock))
    21  	t.Logf("ne1 value sizeof: %d", unsafe.Sizeof(ne1.(*nodeElement[int]).value))
    22  
    23  	ne2 := nodeElement[int]{}
    24  	t.Logf("ne2 alignment: %d", unsafe.Alignof(ne2))
    25  	t.Logf("ne2 next ptr alignment: %d", unsafe.Alignof(ne2.next))
    26  	t.Logf("ne2 prev ptr alignment: %d", unsafe.Alignof(ne2.prev))
    27  	t.Logf("ne2 list ptr alignment: %d", unsafe.Alignof(ne2.list))
    28  	t.Logf("ne2 lock ptr alignment: %d", unsafe.Alignof(ne2.lock))
    29  	t.Logf("ne2 value alignment: %d", unsafe.Alignof(ne2.value))
    30  	t.Logf("ne2 sizeof: %d", unsafe.Sizeof(ne2))
    31  	t.Logf("ne2 next ptr sizeof: %d", unsafe.Sizeof(ne2.next))
    32  	t.Logf("ne2 prev ptr sizeof: %d", unsafe.Sizeof(ne2.prev))
    33  	t.Logf("ne2 list ptr sizeof: %d", unsafe.Sizeof(ne2.list))
    34  	t.Logf("ne2 lock ptr sizeof: %d", unsafe.Sizeof(ne2.lock))
    35  	t.Logf("ne2 value sizeof: %d", unsafe.Sizeof(ne2.value))
    36  
    37  	ne3 := nodeElement[string]{}
    38  	t.Logf("ne3 alignment: %d", unsafe.Alignof(ne3))
    39  	t.Logf("ne3 next ptr alignment: %d", unsafe.Alignof(ne3.next))
    40  	t.Logf("ne3 prev ptr alignment: %d", unsafe.Alignof(ne3.prev))
    41  	t.Logf("ne3 list ptr alignment: %d", unsafe.Alignof(ne3.list))
    42  	t.Logf("ne3 lock ptr alignment: %d", unsafe.Alignof(ne3.lock))
    43  	t.Logf("ne3 value alignment: %d", unsafe.Alignof(ne3.value))
    44  	t.Logf("ne3 sizeof: %d", unsafe.Sizeof(ne3))
    45  }