注册并分享邀请链接,可获得视频播放与邀请奖励。

John Carmack
@ID_AA_Carmack
AGI at Keen Technologies, former CTO Oculus VR, Founder Id Software and Armadillo Aerospace
加入 August 2010
297 正在关注    4.1M 粉丝
I always thought it was a shame that modest default stack setups made alloca() a generally-frowned-upon technique in C/C++. With 64 bit architectures, give every stack a virtual address space equal to the physical memory by default! You can do a surprisingly good job of memory management with just the stack, and I contend that it has both correctness and performance advantages. Allocations are a trivial pointer adjustment, and frees are literally free. Keeping everything linearly packed is friendlier for all layers of the cache hierarchy, and it makes keeping everything in huge / gigantic pages easy. Leaving temporary intermediate blocks on the stack can seem wasteful, but unless you are dealing with algorithms that make > O(n) temporary allocations, it is usually not a big deal. Static analysis can check if you store a stack pointer into a structure deeper in the stack, which is a use-after-free, and then memory management correctness is guaranteed. The discipline of caller-allocates-return is awkward in some dynamic cases. It would take a change in low level calling conventions, but you could plausibly have functions that return with the stack extended from where it was when they were called. I’m not holding my breath for that. It isn’t obvious if having AI coding agents makes discussions of software architecture more or less important!
显示更多
0
148
2.5K
133
转发到社区