In C++, assuming no optimization, do the following two programs end up with the same memory allocation machine code?
int main()
{
int i;
int *p;
}
int main()
{
int *p = new int;
delete p;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, without optimization …
does almost nothing – just a couple of instructions to adjust the stack pointer, but
allocates a block of memory on heap and then frees it, that’s a whole lot of work (I’m serious here – heap allocation is not a trivial operation).