I don't think I'll ever use _alloca (or _malloca) because I can't seem to figure out why it would ever be beneficial. That lends me to think that I just don't understand why it's there. What is the benefit/disadvantages of the two lines below? Don't they both allocate space on the stack of 4 bytes and get popped at the end of scope and/or function scope? They both also result in pointers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | unsigned char a[4]; // no asm generated (?) // removed cast in case it generated extra asm // char* b = (char*)_alloca(4); void* b = _alloca(4); 0130142B mov eax,dword ptr [ebp-11Ch] 01301431 call __alloca_probe_16 (013011F4h) 01301436 mov dword ptr [ebp-120h],esp 0130143C lea ecx,[ebp-54h] 0130143F push ecx 01301440 mov edx,dword ptr [ebp-11Ch] 01301446 mov ecx,dword ptr [ebp-120h] 0130144C call @_RTC_AllocaHelper@12 (01301037h) 01301451 add dword ptr [ebp-120h],20h 01301458 mov edx,dword ptr [ebp-120h] 0130145E mov dword ptr [b],edx |