Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is similar to "stack promotion" in Swift (http://fossies.org/linux/swift-swift/lib/LLVMPasses/LLVMStac...).

Objects that can be determined to stay within a local scope get allocated on the stack instead of a heap, so cleanup is very efficient.

The difference with Go is that decision is done at compile time in Swift and in runtime in Go.



Actually no. Go compiler already has "stack promotion" (using "escape analysis"). TOC is in addition to that and I think it's intended to cover the cases not covered by "stack promotion" for example Function A calls Function B which allocates some memory and returns it to Function A which "consumes it" before returning. In this case the allocation can't be promoted to stack because B returns and its stack gets destroyed.. but the allocated memory can still be safely released when Function A returns.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: