Catch unwanted heap allocations at compile-time #5371
Replies: 2 comments 11 replies
|
Please explain why Also, should a hypothetical type MaybeAllocator interface {
MaybeAllocate()
}
//go:heap
func MustNotAllocate(o MaybeAllocator)In short, a pragma cannot statically determine allocations with precision, unlike |
|
For Using |
Uh oh!
There was an error while loading. Please reload this page.
I have a project where certain code needs to run at a high rate (~1 kHz). I want this code to have zero heap allocations to ensure that GC doesn't affect this high-rate flow.
In golang a programmer generally has very little (if any) control on where the memory is allocated (moreover, sometimes the decisions the compiler makes are non-obvious (see e.g. #5366 where two almost identical pieces of code produced different memory allocation pattern).
What I'd like to have as part of TinyGo is a way to declare a certain function "heap allocation free" which would force the compiler to throw an error if it can't allocate an object on stack.
All reactions