Re: Why does std::stack::pop() not throw an exception if the stack
is empty?
On 10.02.2011 00:54, Joshua Maurice wrote:
On Feb 6, 12:21 am, Joshua Maurice<joshuamaur...@gmail.com> wrote:
On Feb 5, 10:27 pm, Andre Kaufmann<akfmn...@t-online.de> wrote:
[...]
Here's the disassembly output from the visual studios debugger. I'm
not sure what all of that means. I can barely follow it even with
googling some of the opcodes. I ask you to please make sense of it.
Thank you posting the outputs.
So far the code seems to be ok.
Some minor differences (different registers etc.). But not the typical
exception stack initialization and keeping track of created objects as
it's the case for Windows x86 and VC++.
I still wonder why you see differences between calling your test program
with different parameters under Windows x64 -
perhaps we are discussing different things ?
Do you experience with parameters:
60000 -10
and
60000 -10 1
different timings ?
(I deactivated the outputs, but used a global variable to fake the
optimizer).
The only difference between my settings, I deactivated the security
cookie code generation.
And ack. Remind me to copy the full disassembly next time. Forgot to,
and I don't have access to that computer for a while now.
Some code is missing but I don't think it's relevant.
E.g. for the code:
void throwit() { throw 1; }
struct v
{
v(int argc) { if (argc > 3) throwit(); }
~v() { printf("destroyed\r\n"); }
};
int _tmain(int argc, char* argv[])
{
try
{
v v1(argc+1);
v v2(argc+2);
v v3(argc+3);
v v4(argc+4);
v v5(argc+5);
}
catch(...)
{
printf("Exception");
}
return 0;
}
The relevant x86 assembly code would be:
Initialization of the exception stack: [fs] cpu segment register
mov eax,dword ptr fs:[00000000h]
push eax
mov dword ptr fs:[0],esp
And to keep track of created objects
mov byte ptr [ebp-4], x [x=0..]
(I omit the code for deinitialization - restoration of exception stack
at the end of the function)
This surely is the old "Use exception stack to keep track of created
objects" method. In x64 code this tracking is not used, therefore there
should no (significant) overhead between code using exceptions and code
which doesn't use exceptions.
And this should be the same (comparable) implementation as for GCC under
Linux. At least I don't know any better (faster) code, than code which
isn't executed ;-)
Andre