Coffeehouse Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

??? High Memory usage

Back to Forum: Coffeehouse
  • User profile image
    magicalclick

    This is so odd. I am just making this

    bool[] Test = new bool[300000000];

    In my empty WPF app. It is 300million array size. And it takes 300MB instead of 30MB. Why is that so? I am using bool, which is only 1 bit. What is going on?

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    Sven Groot

    Booleans are actually one byte big. Though you could conceivable store them as a single bit and pack 8 of them in a byte, .Net does not do this (it's rare that this is automatic; in C++, vector<bool> does this). So a bool array with 300 million elements uses 300 million bytes.

    If you want to store them as individual bits, use the BitArray class. Note that although this saves you memory, accessing the values can be quite a bit more expensive due to the shift operations required.

     

  • User profile image
    magicalclick

    Thank you for clearing that up. I will check out BitArray class. I actually have 3billions characters long array, so, yeah, I really need to squeez every thing haha.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    magicalclick

    BTW, this is so odd, BitArray has some kind of crazy optimization? I treid to set all true, all false, or alternate ture+false. Their barely use any storage. This is kind of crazy.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    spivonious

    , magicalclick wrote

    Thank you for clearing that up. I will check out BitArray class. I actually have 3billions characters long array, so, yeah, I really need to squeez every thing haha.

    Maybe a linked list would be a better choice for this case, depending on whether or not you need indexed access.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.