<div dir="ltr">Probably to avoid stack overflows, _malloca allocates from the heap rather than from the stack if the size exceeds a threshold. That's why you have to call _freea. I assume that _freea inspects the address or some internals about the allocated memory and then either does nothing for stack memory or does something like free() for heap memory...<div><br></div><div>It might be justified to let the compiler always insert _freea automatically (it would have to make sure not to mix implementations though), but this is C and C programmers love to do everything by themselves, don't they? ;-) It would mean a special case for the compiler, but on the other hand if _alloca and _malloca are usually built-ins, they are already special cases. Still there might be some portability concerns if the C standard (which does not even include alloca...) does not require that a C compiler insert _freea automatically.<br></div><div><br></div><div>During this Internet research I have also seen a mention that alloca() is in some environments replaced with a fallback library implementation that uses heap memory. And that you have to call alloca(0) every now and then to release the memory. So much for portability.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Sa., 31. Dez. 2022 um 00:41 Uhr schrieb Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 30, 2022 at 2:51 PM Jakob Reschke <<a href="mailto:jakres%2Bsqueak@gmail.com" target="_blank">jakres+squeak@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr">That's why (quoted from the doc page):<div><br></div><div><span style="color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px">Unlike </span><span style="box-sizing:inherit;outline-color:inherit;font-weight:600;color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px"><code style="box-sizing:inherit;outline-color:inherit;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.6px;direction:ltr;border-radius:3px;padding:0.1em 0.2em">_alloca</code></span><span style="color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px">, which doesn't require or permit a call to </span><span style="box-sizing:inherit;outline-color:inherit;font-weight:600;color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px"><code style="box-sizing:inherit;outline-color:inherit;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.6px;direction:ltr;border-radius:3px;padding:0.1em 0.2em">free</code></span><span style="color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px"> to free the memory so allocated, </span><span style="box-sizing:inherit;outline-color:inherit;font-weight:600;color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px"><code style="box-sizing:inherit;outline-color:inherit;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.6px;direction:ltr;border-radius:3px;padding:0.1em 0.2em">_malloca</code></span><span style="color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px"> requires the use of </span><a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/freea?view=msvc-170" style="box-sizing:inherit;text-decoration:none;font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px" target="_blank"><code style="box-sizing:inherit;outline-color:inherit;font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:1em;direction:ltr">_freea</code></a><span style="color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:16px"> to free memory.</span></div></div></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Still not a good enough justification, IMO.  They could modify the compiler to plant a call to _freea on return.  I'm also curious to see if _freea actually does anything.  The whole point of alloca is that deallocation is automatic on return because the memory is stack allocated.</div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Am Fr., 30. Dez. 2022 um 23:07 Uhr schrieb Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>>:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr"><div dir="ltr"><div style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 19, 2022 at 9:29 AM Ron Teitelbaum <<a href="mailto:ron@usmedrec.com" target="_blank">ron@usmedrec.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr"><div>Just saw this: <br><a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/alloca?view=msvc-170" target="_blank">https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/alloca?view=msvc-170</a><br><br>_alloca<br><br>Article<br>10/26/2022<br><br>Allocates memory on the stack. This function is <b>deprecated</b> because a more secure version is available; see:</div><div><br></div><div> <a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/malloca?view=msvc-170" style="background-color:rgba(0,0,0,0);font-size:16px;font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;box-sizing:inherit;text-decoration:none" target="_blank"><code style="box-sizing:inherit;outline-color:inherit;font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:1em;direction:ltr">_malloca</code></a><span style="font-size:16px;color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif">.</span></div></div></blockquote><div><br></div><div style="font-size:small">Mucroshaft are such irritating *FUCKS*.  It has exactly the same signature as alloca.  Why didn't they just upgrade the implementation instead of forcing everyone to rewrite their code??</div><div style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div><br></div><div><a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/malloca?view=msvc-170" target="_blank">https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/malloca?view=msvc-170</a><span style="font-size:16px;color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif"><br></span></div><div><span style="font-size:16px;color:rgb(23,23,23);font-family:"Segoe UI",SegoeUI,"Helvetica Neue",Helvetica,Arial,sans-serif"><br></span></div>Requirements<br><br>RoutineRequired header<br>_malloca<malloc.h><div><br></div><div><div style="font-size:small">All the best,</div><div style="font-size:small"><br></div><div style="font-size:small">Ron Teitelbaum</div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 19, 2022 at 12:00 PM Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de" target="_blank">marcel.taeumel@hpi.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div id="m_-5349872157697803519m_-3353100835723712508m_4421183224645212577m_6153784794402318685m_-4689773844851336570__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0);text-align:left" dir="ltr">Hi all!<div></div><div><br></div><div>Has anybody tried to build OSVM in Windows 11 via Cygwin64?</div><div><br></div><div>clang-8 does not work because "_alloca" cannot be found ... hmm...</div><div><br></div><div><img id="m_-5349872157697803519m_-3353100835723712508m_4421183224645212577m_6153784794402318685m_-468977384485133657068a5a786-310e-4df1-9e93-a3fc98e26ddd" src="cid:1852b6ade0bcb971f161" width="355" style="font-size: 10pt;" height="154"></div><div><br></div><div>So, who implements _alloca? It's not msvcrt.dll ... how to find that out?</div><div><br></div><div>Best,</div><div>Marcel</div></div></blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div>
</blockquote></div>