4 ms·
There is a linter for this I believe. There can never be an automated fix for this since code can depend on the memory layout. Anyway, this is common in progra
by AtNightWeCode 5y ago
There is a linter for this I believe. There can never be an automated fix for this since code can depend on the memory layout.
Anyway, this is common in programming. At least it was not 4 bytes for the alignment.
Things like this also impact performance. We had a project where we lost both memory and speed after migrating to C++. Turned out to be the virtual destructor that was the culprit.
- mariusor 5y ago> There can never be an automated fix for this since code can depend on the memory layout. I think that's very specifically discouraged in Go, unless there's a way to do it without using the "unsafe" package that I don't know of: > Package unsafe contains operations that step around the type safety of Go programs. > Packages that import unsafe may be non-portable and are not protected by the Go 1 compatibility guidelines.
- AtNightWeCode 5y agoI would not be surprised if somethings may break if there is a discrepancy between the structs and the memory layout. Stranger things have been seen. If people followed best practices, there would not be a problem in the first place. How to work with and check memory alignment is very much a known area. …and I do believe there is linter for this in Go as well.