我试图在C++程序中节省一些内存,我想知道我是否可以使用块作为变量的范围(如Perl).假设我有一个巨大的对象执行一些计算并给出结果,这样做是否有意义:
InputType input;
ResultType result;
{
// Block of code
MyHugeObject mho;
result = mho.superHeavyProcessing();
}
/*
My other code ...
*/
Run Code Online (Sandbox Code Playgroud)
退出块时,我可以期望对象被销毁吗?