当前位置:网站首页>The use of go unsafe
The use of go unsafe
2022-06-23 21:28:00 【It workers】
Explain not to arrange pointers for :
unsafe.Pointer In fact, it's similar C Of void *, stay golang Is used for a variety of pointer conversion bridge .uintptr yes golang Built in type , It's an integer that can store pointers ,uintptr The bottom type of is int, It and unsafe.Pointer Can be converted to each other .
Under normal circumstances go Structure private variables in a language cannot be accessed or modified directly , But it can go through unsafe To directly access or modify any variable
package main
import (
_ "ORMTest/routers"
"fmt"
"unsafe"
)
func main() {
d := struct {
s string
i int
}{"abc", 100}
p := uintptr(unsafe.Pointer(&d)) // *struct -> Pointer -> uintptr
p += unsafe.Offsetof(d.s) // uintptr + offset
p2 := unsafe.Pointer(p) // uintptr -> Pointer
px := (*int)(p2) // Pointer -> *int
*px = 200 // d.s = 200
fmt.Printf("%#v\n", d)
}Output :
{s string;x int}{s:"abc",x:200}
边栏推荐
- Wechat is new. You can create applications from Excel
- JS to get the screen size, current web page and browser window
- What are the advantages of attaching a virtual machine to a hard disk cloud server
- Global and Chinese markets of natural starch 2022-2028: Research Report on technology, participants, trends, market size and share
- 上线项目之局域网上线软件使用-----phpStudy
- Where should DNS start? I -- from the failure of Facebook
- Polling and connection
- What software is safe to use to fight new debts? What are the new bond platforms
- Advantages of token mechanism over cookie mechanism
- Talk about how to customize data desensitization
猜你喜欢

Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis

How to view the role of PMO in agile organizations?

Steps for formulating the project PMO strategic plan

I am 30 years old, no longer young, and have nothing

Facing the problem of lock waiting, how to realize the second level positioning and analysis of data warehouse

New SQL syntax quick manual!
Application of JDBC in performance test

Four aspects of PMO Department value assessment

Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create

How to gradually improve PMO's own ability and management level
随机推荐
Yukeng MySQL service installation error
Using clion to realize STM32F103 lighting LED
Pathname attribute of link a object
Wechat smart operation 3.0+ Alipay digital transformation 3.0
2021 three "myths" of science and technology industry -- yuancosmos, NFT and web 3
我在深圳,到哪里开户比较好?在线开户安全么?
The new track of flagship chip is finally clear
Gradle asked seven times. You should know that~
Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create
Go local variables & global variables
JS to get the screen size, current web page and browser window
How to define an "enumeration" type in JS
Global and Chinese market of gas fire pit 2022-2028: Research Report on technology, participants, trends, market size and share
SAP retail wrmo replenishment monitoring
Short video intelligent audit software intelligent audit or manual audit
It's very interesting. Make an app to decorate the Christmas hat on Christmas!
[JS reverse hundred examples] anti climbing training platform for netizens question 6: JS encryption, environment simulation detection
Overview of digital circuits
【Redis】有序集合的交集与并集
Disaster recovery series (VII) -- hybrid cloud public network export disaster recovery construction