31

So today I saw this guy:

long size = long.MaxValue;
//method that may or may not set
//size

int[] array = new int[size];

Apparently we are processing blu-ray movies in place in memory.

Comments
  • 2
    He should have used List<int> = new List<int>{};
    Seriously, he probably wanted infinite indexes, so...
  • 0
    (okay, you also need

    using System.Collections.Generic;

    for that)
  • 2
    made me think..
    int[long.MaxValue] should be the same size as long[int.MaxValue] right?

    since x*2x == 2x*x

    🤔
  • 1
    @filthyranter I just yanked it out and initiated to 0 and added guard if statements. Size didn't need to be a long. I originally went the list route, but it was just taking image pixel data, so you only needed to set the size once. It was just amazing to me, especially since this was originally written for machines with like a gig of RAM max so a failure to set size would have led to the app trying to allocate 8+ gigs of RAM.

    @xalez in C# longs are 64 bit.
  • 4
    @xalez not even close. Long has 2x more bits, so its' max value increases 2^x times
  • 1
    @sSam aaakh.. I feel dumb .. guess I shouldn't be doing much thinking when half asleep :/
  • 0
    Yeah, I calculated out the size of this array if it was allocated 100% in that call. It was somethin ? Like 8.8 gigs.
Add Comment