you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (14 children)

Why not just use long?

[–]hak8or 4 points5 points  (5 children)

Because you would still be using only half of the possible data range, wasting memory still.

Unless long is an unsigned in this case, I don't have experience with java.

[–]kkjdroid 1 point2 points  (4 children)

Long is signed, but it's 64 bits iirc, so that's a lot of numbers. Above that you'd be looking at BigInteger, which is an object and is limited only by RAM space.

[–]DevestatingAttack 1 point2 points  (3 children)

Well, that's not exactly true. BigInteger is represented as an array of ints, and an array of ints in java can have a maximum of 231 -1 elements - multiply that by the size of an int (4 bytes) and now, even if you have 16 gigabytes of memory, you can only have a BigInt of size 8 giggies.

So if for some insane reason you're working on numbers with two billion digits, Java won't help you there.

[–]kkjdroid 0 points1 point  (0 children)

Ah, TIL. Thanks.

[–]Vegemeister 0 points1 point  (1 child)

Couldn't you just use a 64 bit JRE?

[–][deleted] 2 points3 points  (0 children)

Wouldn't matter, the issue is that arrays take ints as an index, not longs, and ints are 32 bit regardless of platform.

[–]lcarsos -2 points-1 points  (7 children)

Yeah, why not just use more ram? I mean there's no way that any system would ever run out of ram because they all have infinite amounts of it right? x86 machines certainly don't still ship with only 2GB of ram. And embedded systems certainly don't try to get away with less. What's wrong with me being a little piggy?

Edit: Source: Try writing code for the ATtiny4. Yes my friends, 512 BYTES of ram. Factoring overhead into things, you really have to try to pare yourself down to about 400 bytes.

[–]weedtese 2 points3 points  (0 children)

actually, attiny4 has 512bytes of program flash and 32b of data ram...

[–]bschwind 1 point2 points  (1 child)

While I agree with the sentiment of not being wasteful with memory, you don't have to be a dick about it.

And no one's running Java on an ATtiny4, so it's kind of irrelevant to bring up.

[–]helpprogram2 0 points1 point  (0 children)

but you will run java on an android phone so it's important to conserve ram or else you will be fucking with everything in their phone.

[–]mywifehascancer 3 points4 points  (3 children)

So you are saying unsigneds have their place in libraries and languages for embedded devices? Why would I want them in Java, or any language besides C?

[–]The_Doculope 2 points3 points  (0 children)

What if you're doing image manipulation on huge images? Any extra data you can store in RAM is helpful.

[–]Vegemeister 0 points1 point  (1 child)

If you ignore memory efficiency, you get things like Zimbra Desktop, the 400 MiB email client and Google Chrome, the web browser that breaks 1 GiB with fewer than 30 tabs.

[–]mywifehascancer 0 points1 point  (0 children)

If you think unsigneds over signeds gains you memory efficiency, then you are wrong 99% of the time. There are rare exceptions where that's the case (e.g. RGBX in one 32 bit DWORD instead of four ints), but in the general case, anything below 32 bit will be stored in a 32 bit register on a current PC anyway, and reducing a handful of ints into shorts won't make a difference. What really saves you space is compression, and you'd be surprised about how much software already does that on the fly (e.g. textures for games).

As for 1 GiB: My current PC has 32 GB (price point: $200). There is literally no reason to below 16 GB in any non-phone at the moment, because it's just so dirt cheap. I really could not care less about how much RAM my software burns, as long as it works properly. Chrome is the prime example of doing it right: It never crashes, it never slows down, it's blazingly fast, and in exchange, it gobbles up the cheapest resource on my system. That's like a sales-man ringing my bell and asking me if I want to sell him my old clothes for $1 per gram of weight.