Does newByteArray clear?

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

Does newByteArray clear?

David Feuer
I'm looking to play around with an array-based structure with sub-linear worst-case bounds. Array is pretty awkward in that context because creating a new one takes O(n) time to initialize it. Is that all true of newByteArray, or can I get one with arbitrary garbage in it for cheap?

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Does newByteArray clear?

Haskell - Glasgow-haskell-users mailing list
David Feuer wrote:
> I'm looking to play around with an array-based structure with
> sub-linear worst-case bounds. Array is pretty awkward in that context
> because creating a new one takes O(n) time to initialize it. Is that
> all true of newByteArray, or can I get one with arbitrary garbage in it
> for cheap?

newByteArray# does not actively clear memory.

However, for large arrays, I think the memory is likely to be freshly
allocated from the OS, and the OS will have cleared it for security
reasons.

Cheers,

Bertram
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Does newByteArray clear?

David Feuer
Thanks! I'm still going to feel free to pretend I get arrays for free :-). I'm guessing I'll get some reused ones from the Haskell allocator, and the OS is of course free to do clearing work on another core. It'd be awfully nice to have a way to get "incrementally-cleared" arrays of pointers, but that would require a new heap object type, which would be a lot to ask for.

On Wed, Aug 26, 2020, 8:56 PM Bertram Felgenhauer via Glasgow-haskell-users <[hidden email]> wrote:
David Feuer wrote:
> I'm looking to play around with an array-based structure with
> sub-linear worst-case bounds. Array is pretty awkward in that context
> because creating a new one takes O(n) time to initialize it. Is that
> all true of newByteArray, or can I get one with arbitrary garbage in it
> for cheap?

newByteArray# does not actively clear memory.

However, for large arrays, I think the memory is likely to be freshly
allocated from the OS, and the OS will have cleared it for security
reasons.

Cheers,

Bertram
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Does newByteArray clear?

Bardur Arantsson-2
In reply to this post by Haskell - Glasgow-haskell-users mailing list
On 27/08/2020 02.56, Bertram Felgenhauer via Glasgow-haskell-users wrote:

> David Feuer wrote:
>> I'm looking to play around with an array-based structure with
>> sub-linear worst-case bounds. Array is pretty awkward in that context
>> because creating a new one takes O(n) time to initialize it. Is that
>> all true of newByteArray, or can I get one with arbitrary garbage in it
>> for cheap?
>
> newByteArray# does not actively clear memory.
>
> However, for large arrays, I think the memory is likely to be freshly
> allocated from the OS, and the OS will have cleared it for security
> reasons.
>

Not sure how common it is in practice, but it's worth noting that OS'es
should be able to clear freed memory as a background process, so that
they don't have to do it on demand at the precie point of allocation. Of
course this depends on memory churn, etc. etc., so it's not exactly
guaranteed even if the OS supports it.

Regards,

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users