当前位置:网站首页>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}
边栏推荐
- Processing of purchase return in SAP mm preliminary transaction code Migo
- [redis] intersection and union of ordered sets
- Excel text function
- JS to get the screen size, current web page and browser window
- How to define an "enumeration" type in JS
- How to batch generate UPC-A codes
- Global and Chinese markets for e-cigarettes and tobacco vapors 2022-2028: Research Report on technology, participants, trends, market size and share
- SAP FICO as03 display fixed assets master data
- How to solve the problem that the ID is not displayed when easycvr edits the national standard channel?
- Go local variables & global variables
猜你喜欢

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

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

How PMO uses two dimensions for performance appraisal
Application of JDBC in performance test

I am 30 years old, no longer young, and have nothing
![Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text](/img/b1/71cc36c45102bdb9c06e099eb42267.jpg)
Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text

Four aspects of PMO Department value assessment

Gradle asked seven times. You should know that~

Steps for formulating the project PMO strategic plan

Facing the problem of lock waiting, how to realize the second level positioning and analysis of data warehouse
随机推荐
Full instructions for databinding
Initial experience of nodejs express framework
Machine learning related
Drawing STM32 minimum system schematic diagram with AD
Beitong G3 game console unpacking experience. It turns out that mobile game experts have achieved this
The element of display:none cannot get offsetwidth and offsetHeight
How to build a personal cloud game server? How many games can the cloud game platform install?
[typescript] some summaries in actual combat
What is the main content of short video audit? What is illegal?
[JS reverse hundred examples] anti climbing training platform for netizens question 6: JS encryption, environment simulation detection
How to reduce snapshots
How to build a cloud game platform on the server? How to select a cloud game server?
Wechat is new. You can create applications from Excel
手机卡开户的流程是什么?在线开户安全么?
How to expand the capacity of ECS disk? What are the advantages of using cloud disk
Authentication can be as simple as this - use the API gateway to protect your API security
Infrastructure splitting of service splitting
How to Net project migration to NET Core
[Debian] Debian usage notes
Global and Chinese market of fly killers 2022-2028: Research Report on technology, participants, trends, market size and share