This is a multi-part message in MIME format.
--------------040806050400080602040807
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

A common technique is to allocate a reasonably sized array (256-bytes)
on the C stack and zero it before and after each allocation.  This
reduces garbage left on the stack before and after allocation and
possible GC:

void *my_alloc(size_t size)
{
   char zeros[256];
   void *ptr;
   memset(zeros, 0, sizeof(zeros));
   ptr  y_alloc_inner(size);
   memset(zeros, 0, sizeof(zeros));
   return ptr;
}

void *my_alloc_inner(size_t size)
{
   /* may call GC */
}

Might need to put my_alloc_inner() in a separate compilation unit to
avoid inlining.

Kurt

Brent Roman wrote:
> Martin,
>
> Well.  Ummm.  If a compiler writes zeros then is it not setting the
> value of variables that the spec says should remain undefined until
> explicitly initialized? 
>
> Whether or not it violates the 'C' language spec, I don't know any way to 
> make gcc do this with existing compiler options or pragmas.
>
> Does anyone else?
>
> - brent
>
>
>
> Martin Duerst wrote:
>   
>> At 12:54 08/11/17, Brent Roman wrote:
>>
>>     
>>> One could hack the gcc to force it to initialize automatic variables to
>>>       
> zero 
>   
>>> even though this violates the 'C' langauage spec.
>>>       
>> I haven't read the spec, but my guess (having worked on other specs)
>> is that the only thing that the 'C' language spec says is that the
>> value is undefined. A value that happens to be zero would still be
>> undefined, as far as I understand.
>>
>> Regards,    Martin.
>>
>>
>>
>> #-#-#  Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University
>> #-#-#  http://www.sw.it.aoyama.ac.jp       mailto:duerst / it.aoyama.ac.jp     
>>
>>
>>
>>
>>     
>
>   


--------------040806050400080602040807
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta contentext/html;charsetO-8859-1" http-equiv
ontent-Type"> </head> <body bgcolorffffff" text000000"> A common technique is to allocate a reasonably sized array (256-bytes) on the C stack and zero it before and after each allocation.&nbsp; This reduces garbage left on the stack before and after allocation and possible GC:<br> <br> void *my_alloc(size_t size)<br> {<br> &nbsp;&nbsp; char zeros[256];<br> &nbsp;&nbsp; void *ptr;<br> &nbsp;&nbsp; memset(zeros, 0, sizeof(zeros));<br> &nbsp;&nbsp; ptr y_alloc_inner(size);<br> &nbsp;&nbsp; memset(zeros, 0, sizeof(zeros));<br> &nbsp;&nbsp; return ptr;<br> }<br> <br> void *my_alloc_inner(size_t size)<br> {<br> &nbsp;&nbsp; /* may call GC */<br> }<br> <br> Might need to put my_alloc_inner() in a separate compilation unit to avoid inlining.<br> <br> Kurt<br> <br> Brent Roman wrote: <blockquote citeid:20538247.post / talk.nabble.com" type
ite"> <pre wrap>Martin, Well. Ummm. If a compiler writes zeros then is it not setting the value of variables that the spec says should remain undefined until explicitly initialized? Whether or not it violates the 'C' language spec, I don't know any way to make gcc do this with existing compiler options or pragmas. Does anyone else? - brent Martin Duerst wrote: </pre> <blockquote type
ite"> <pre wrap>At 12:54 08/11/17, Brent Roman wrote: </pre> <blockquote type
ite"> <pre wrap>One could hack the gcc to force it to initialize automatic variables to </pre> </blockquote> </blockquote> <pre wrap><!---->zero </pre> <blockquote type
ite"> <blockquote type
ite"> <pre wrap>even though this violates the 'C' langauage spec. </pre> </blockquote> <pre wrap>I haven't read the spec, but my guess (having worked on other specs) is that the only thing that the 'C' language spec says is that the value is undefined. A value that happens to be zero would still be undefined, as far as I understand. Regards, Martin. #-#-# Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University #-#-# <a classoz-txt-link-freetext" hrefttp://www.sw.it.aoyama.ac.jp">http://www.sw.it.aoyama.ac.jp</a> <a classoz-txt-link-freetext" hrefailto:duerst / it.aoyama.ac.jp">mailto:duerst / it.aoyama.ac.jp</a> </pre> </blockquote> <pre wrap><!----> </pre> </blockquote> <br> </body> </html> --------------040806050400080602040807--