4 ms·
Isn't it the case that the compiler allocates objects on the heap if the reference escapes the function, and allocates on the stack if the reference doesn't?
by linkregister 9y ago
Isn't it the case that the compiler allocates objects on the heap if the reference escapes the function, and allocates on the stack if the reference doesn't?
- masklinn 9y ago> if the reference escapes the function The difficulty is knowing when that happens, and you're probably guessing wrong (the -m gcflag will tell you). Furthermore fitting Go's theme the escape analysis is pretty simplistic, so there are many cases where it will somewhat unexpectedly assume escape (note: link is from 1.15, some have been fixed since like the …arg one or the slice assignment): https://docs.google.com/document/d/1CxgUBPlx9iJzkz9JWkb6tIpTe5q32QDmz8l0BouG0Cw/preview# https://docs.google.com/document/d/1CxgUBPlx9iJzkz9JWkb6tIpT...