922 karma · joined Aug 18, 2014 (12y ago) · 345 submissions
comment 2y ago · link · parent
Link for the lazy
comment 2y ago · link · parent
Don't feel bad, I've tried to do this in some places, but I'm not sure it's worth it. It adds a ton of boilerplate to Go's already verbose error handling, since you need to wrap every error that gets returned from libraries.
comment 2y ago · link · parent
comment 2y ago · link · parent
Maybe? But that seems strange, since they seem to have intended it to be used for http servers making per-request allocations.
Come to think of it, the arena is probably still unsound with just ints, because the underlying allocation is just for a `[]byte`, which I don't think is guaranteed to be aligned to 8 bytes. Might be on most platforms, though.
comment 2y ago · link · parent
It is not. Arena allocators have a fundamentally different API, because they don't allow you to de-allocate individual objects in the arena - everything must be de-allocated at once. For specific workloads, like repeatedly allocating a large number of short-lived objects, this can be a huge speedup, and also significantly reduce memory usage.
comment 2y ago · link · parent
arena := NewSlabArena(8182, 1) // 8KB
var b *byte = New[byte](arena)
var i *int = New[int](arena)
fmt.Printf("Pointer address: %p\n", b)
fmt.Printf("Pointer address: %p\n", i)
Result: Pointer address: 0x14000198000
Pointer address: 0x14000198001
I'm not a Go language lawyer, but I assume this is just immediate UB. OP, it's fine to publish a library without experience in manual memory management, but maybe put a disclaimer in the README?comment 2y ago · link · parent
> Languages where parallelism is memory safe, but can still lead to data races.
> This includes Java and Go.
Despite this common misconception, parallel Go is absolutely not memory safe: https://blog.stalkr.net/2015/04/golang-data-races-to-break-m...
comment 2y ago · link · parent
I can safely assure you that this is bullshit. Any electric car will use well over 1 Kwh to travel that distance. You can run two high-end GPUs for an hour with that amount of electricity. You're not spending two hours of GPU-time to generate your images.
comment 2y ago · link · parent
comment 2y ago · link · parent
Isn't this exactly what the author's point #2 ("More and better infrastructure lets us spread out and enjoy more space") was about?
comment 2y ago · link · parent
comment 2y ago · link · parent
Do you some intuition of what causes this? I don't have how much experience with this kind of work, but 100µs is enough time to do hundreds of random memory accesses. How can a single syscall do so much damage to the cache?
comment 2y ago · link · parent
Thank you for articulating this, I also don't understand why the author puts operator overloading in the same bucket as exceptions and `defer()`. Yes, `+` might call a function, but it will never affect the control flow of the parent function. Not more than a regular function call, at least.