Questions tagged «stack-allocation»

1
为什么在不使用堆栈内存时分配堆栈内存?
考虑以下示例: struct vector { int size() const; bool empty() const; }; bool vector::empty() const { return size() == 0; } 生成的汇编代码vector::empty(通过clang,带有优化): push rax call vector::size() const test eax, eax sete al pop rcx ret 为什么要分配堆栈空间?完全不使用。该push和pop可以省略。优化的MSVC和gcc构建也为此功能使用了堆栈空间(请参阅godbolt),因此必须有一个原因。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.