No subject


Tue Jan 15 14:41:49 EST 2013


DESCRIPTION
     The alloca() macro allocates size bytes of space in the stack frame of=
 the caller.  This temporary space is automatically freed on return.

I am planning on using it for some dimension sized array in compiled templa=
teless code, in lieu of C99 dynamic stack based arrays.

Best as I can tell Windows defines it as _alloca, so a little CMake try com=
pile is going to be needed, not a big deal.

Thanks,
Brad
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by th=
e Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidenti=
al and may be legally privileged.  If you are not the intended recipient, y=
ou are hereby notified that any retention, dissemination, distribution, or =
copying of this communication is strictly prohibited.  Please reply to the =
sender that you have received the message in error, then delete it.  Thank =
you.
________________________________

--_000_CD64D9963644Fnormankwilliamsuiowaedu_
Content-Type: text/html; charset="us-ascii"
Content-ID: <697DDB32A5A06E4AA7ADB31E3497D3B1 at mailhost6.uiowa.edu>
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
</head>
<body style=3D"word-wrap:break-word">
<div>
<div><font class=3D"Apple-style-span" face=3D"Consolas,monospace">I can't t=
hink of a single reason in ITK to use alloca. Pretty much every use case fo=
r alloca can be implemented using C&#43;&#43; language features in a more r=
obust manner.</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace"><br>
</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace">Maybe it'=
s unfair to say, but I think that the only reason it hasn't fallen out of u=
se entirely is the esteem in which it
 is held by certain programmers associated with the GNU project. That's the=
 one place it crept into VTK -- a bison-generated parser they've been modif=
ying for years.</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace"><br>
</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace">The follo=
wing has been a workaround I've used since C&#43;&#43; hasn't supported dyn=
amically sized arrays in the past -- I believe
 it is a gnu extension (that, by the way, uses alloca under the covers). Of=
 course, in most cases, it is preferable to use a STL container. &nbsp;I do=
n't remember who said it first but it's true: Arrays are to data what goto =
is to code.</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace"><br>
</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace">It is ver=
y nearly as efficient as raw array access, and the actual array is on the h=
eap:</font></div>
<div><font class=3D"Apple-style-span" face=3D"Consolas,monospace">
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><br>
</div>
<div>
<div>#include &lt;cstddef&gt;</div>
<div><br>
</div>
<div>template &lt;typename TElement&gt;</div>
<div>class DynArray</div>
<div>{</div>
<div>public:</div>
<div>&nbsp; typedef std::size_t size_type;</div>
<div>&nbsp; DynArray(size_type numElements) : m_Size(numElements)</div>
<div>&nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; this-&gt;m_Array =3D new TElement[numElements];</=
div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; ~DynArray()</div>
<div>&nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; delete [] this-&gt;m_Array;</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; TElement &amp;operator[](size_type idx)</div>
<div>&nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; if(idx &gt; this-&gt;m_Size)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; throw;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; return this-&gt;m_Array[idx];</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; const TElement &amp;operator[](size_type idx) const</div>
<div>&nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; if(idx &gt; this-&gt;m_Size)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; throw;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; return this-&gt;m_Array[idx];</div>
<div>&nbsp; &nbsp; }</div>
<div>private:</div>
<div>&nbsp; TElement *m_Array;</div>
<div>&nbsp; size_type m_Size;</div>
<div>};</div>
</div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><br>
</div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><br>
</div>
</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace">--&nbsp;<=
/font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace">Kent Will=
iams norman-k-williams at uiowa.edu</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace"><br>
</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace"><br>
</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:1=
4px"><font class=3D"Apple-style-span" face=3D"Consolas,monospace"><br>
</font></div>
<div style=3D"color:rgb(0,0,0); font-family:Consolas,monospace; font-size:1=
2px"><br>
</div>
</div>
<div style=3D"color:rgb(0,0,0); font-family:Consolas,monospace; font-size:1=
2px"><br>
</div>
<div style=3D"color:rgb(0,0,0); font-family:Consolas,monospace; font-size:1=
2px">On 3/12/13 7:54 AM, &quot;Bradley Lowekamp&quot; &lt;<a href=3D"mailto=
:blowekamp at mail.nih.gov">blowekamp at mail.nih.gov</a>&gt; wrote:</div>
<div style=3D"color:rgb(0,0,0); font-family:Consolas,monospace; font-size:1=
2px"><br>
</div>
<blockquote id=3D"MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style=3D"color:rgb(0,=
0,0); font-family:Consolas,monospace; font-size:12px; border-left-color:rgb=
(181,196,223); border-left-width:5px; border-left-style:solid; padding-top:=
0px; padding-right:0px; padding-bottom:0px; padding-left:5px; margin-top:0p=
x; margin-right:0px; margin-bottom:0px; margin-left:5px">
<div>Hello,</div>
<div><br>
</div>
<div>I am thinking about using the &quot;alloca&quot; function in some code=
 I'm working on for ITK, and wonder what other people think of it or others=
 experience...</div>
<div><br>
</div>
<div>From the BSD Library Functions Manual:</div>
<div><br>
</div>
<div>DESCRIPTION</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; The alloca() macro allocates size bytes of sp=
ace in the stack frame of the caller.&nbsp;&nbsp;This temporary space is au=
tomatically freed on return.</div>
<div><br>
</div>
<div>I am planning on using it for some dimension sized array in compiled t=
emplateless code, in lieu of C99 dynamic stack based arrays.</div>
<div><br>
</div>
<div>Best as I can tell Windows defines it as _alloca, so a little CMake tr=
y compile is going to be needed, not a big deal.</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Brad </div>
<div>_______________________________________________</div>
<div>Powered by www.kitware.com</div>
<div><br>
</div>
<div>Visit other Kitware open-source projects at</div>
<div><a href=3D"http://www.kitware.com/opensource/opensource.html">http://w=
ww.kitware.com/opensource/opensource.html</a></div>
<div><br>
</div>
<div>Kitware offers ITK Training Courses, for more information visit:</div>
<div><a href=3D"http://kitware.com/products/protraining.php">http://kitware=
.com/products/protraining.php</a></div>
<div><br>
</div>
<div>Please keep messages on-topic and check the ITK FAQ at:</div>
<div><a href=3D"http://www.itk.org/Wiki/ITK_FAQ">http://www.itk.org/Wiki/IT=
K_FAQ</a></div>
<div><br>
</div>
<div>Follow this link to subscribe/unsubscribe:</div>
<div><a href=3D"http://www.itk.org/mailman/listinfo/insight-developers">htt=
p://www.itk.org/mailman/listinfo/insight-developers</a></div>
<div><br>
</div>
</blockquote>
<br>
<br>
<hr>
Notice: This UI Health Care e-mail (including attachments) is covered by th=
e Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidenti=
al and may be legally privileged.&nbsp; If you are not the intended recipie=
nt, you are hereby notified that any
 retention, dissemination, distribution, or copying of this communication i=
s strictly prohibited.&nbsp; Please reply to the sender that you have recei=
ved the message in error, then delete it.&nbsp; Thank you.
<hr>
</body>
</html>

--_000_CD64D9963644Fnormankwilliamsuiowaedu_--


More information about the Insight-developers mailing list