golang如何打印内存内容

golang如何打印内存内容

package main

import (
    "fmt"
    "unsafe"
)

func main() {
    var v = any_type_variable

    var p uintptr  = uintptr(unsafe.Pointer(&v))
    fmt.Printf("0x%x\n", p)    // print p, i.e., pointer value

    fmt.Printf("0x%x\n", *(* int64)(unsafe.Pointer(p)))    // print content at address p as int64 type

    p += 8
    fmt.Printf("0x%x\n", *(* int64)(unsafe.Pointer(p)))    // move forward 8 bytes(size of int64), and print content of new p

    p += 4
    fmt.Printf("0x%x\n", *(* int)(unsafe.Pointer(p)))      // move forward 4 bytes(size of int), and print content of new p

你可能感兴趣的:(golang如何打印内存内容)