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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Alex Petrov
Hi everyone,

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. Original discussion took a place in `fillBytes` [1] and was 
publicised on that mailing list [2].

Please share your thoughts.

Thank you.





--
alex p

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Edward Kmett-2
+1, 'nuff said. 

I was very surprised they weren't already there, and calloc can be 2x faster than any malloc/set to 0 nonsense.

-Edward

On Sat, Nov 29, 2014 at 11:05 AM, Oleksandr Petrov <[hidden email]> wrote:
Hi everyone,

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. Original discussion took a place in `fillBytes` [1] and was 
publicised on that mailing list [2].

Please share your thoughts.

Thank you.





--
alex p

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries



_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Herbert Valerio Riedel
In reply to this post by Alex Petrov
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
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Austin Seipp-5
I'm also +1 for this addition.

On Sun, Nov 30, 2014 at 2:42 AM, Herbert Valerio Riedel <[hidden email]> 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
> [hidden email]
> http://www.haskell.org/mailman/listinfo/libraries
>



--
Regards,

Austin Seipp, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com/
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Luite Stegeman
In reply to this post by Alex Petrov
+1 here too

additionally for GHCJS this is a no-brainer since ArrayBuffers (used for data storage when Addr# / Ptr is involved) are initialized to 0 on allocation, making calloc no more expensive than malloc.


On Sat, Nov 29, 2014 at 5:05 PM, Oleksandr Petrov <[hidden email]> wrote:
Hi everyone,

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. Original discussion took a place in `fillBytes` [1] and was 
publicised on that mailing list [2].

Please share your thoughts.

Thank you.





--
alex p

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries



_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

John Lato-2
+1, very sensible addition.

On 09:24, Sun, Nov 30, 2014 Luite Stegeman <[hidden email]> wrote:
+1 here too

additionally for GHCJS this is a no-brainer since ArrayBuffers (used for data storage when Addr# / Ptr is involved) are initialized to 0 on allocation, making calloc no more expensive than malloc.


On Sat, Nov 29, 2014 at 5:05 PM, Oleksandr Petrov <[hidden email]> wrote:
Hi everyone,

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. Original discussion took a place in `fillBytes` [1] and was 
publicised on that mailing list [2].

Please share your thoughts.

Thank you.





--
alex p

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

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

Edward Kmett-2
In reply to this post by Herbert Valerio Riedel
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 <[hidden email]> 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
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries