Implement `calloc{,Bytes,Array,Array0}` allocators

Edward Kmett ekmett at gmail.com
Tue Dec 2 08:15:10 UTC 2014


Not only that, calloc often comes from fresh 0-initialized memory that is
just allocated when forced in the memory manager, so it can often get
zeroed for free.

-Edward

On Sun, Nov 30, 2014 at 7:42 PM, Herbert Valerio Riedel <hvr at gnu.org> wrote:

> On 2014-11-29 at 17:05:58 +0100, Oleksandr Petrov wrote:
> > There is a proposal [1] (with implemented revision) to implement
> > zero-initialising
> > versions
> > of malloc{,Bytes,Array,Array0}
> >
> >    - Add calloc and callocBytes to Foreign.Marshal.Alloc.
> >    - Add callocArray and callocArray0 to Foreign.Marshal.Array.
> >
> > The benefit is that you can allocate required amount of memory and be
> > certain that it will be cleared
> > (set with zeroes) before you use it.
>
> +1
>
> (Fwiw, it's not only a convenient combined operation but it also has
> potentially less overhead by requiring only a single FFI-call to
> calloc(3), instead of having to FFI-call twice into libc when doing
> malloc(3)+memset(3))
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141202/b79b0680/attachment.html>


More information about the Libraries mailing list