Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Creating a byte[] of long size

Reply
Thread Tools

Creating a byte[] of long size

 
 
Arne Vajhj
Guest
Posts: n/a
 
      07-10-2010
On 09-07-2010 08:15, Eric Sosman wrote:
> On 7/8/2010 9:11 PM, Patricia Shanahan wrote:
>> Arne Vajhj wrote:
>>> On 08-07-2010 17:35, Boris Punk wrote:
>>>> Integer.MAX_VALUE = 2147483647
>>>>
>>>> I might need more items than that. I probably won't, but it's nice to
>>>> have
>>>> extensibility.
>>>
>>> It is a lot of data.
>>>
>>> I think you should assume YAGNI.

>>
>>
>> Historically, each memory size has gone through a sequence of stages:
>>
>> 1. Nobody will ever need more than X bytes.
>>
>> 2. Some people do need to run multiple jobs that need a total of more
>> than X bytes, but no one job could possibly need that much.
>>
>> 3. Some jobs do need more than X bytes, but no one data structure could
>> possibly need that much.
>>
>> 4. Some data structures do need more than X bytes.
>>
>> Any particular reason to believe 32 bit addressing will stick at stage
>> 3, and not follow the normal progression to stage 4?

>
> None. But Java's int isn't going to grow wider, nor will the
> type of an array's .length suddenly become non-int; too much code
> would break. When Java reaches the 31-bit wall, I doubt it will
> find any convenient door; Java's descendants may pass through, but
> I think Java will remain stuck on this side.
>
> In ten years, we'll all have jobs converting "legacy Java code"
> to Sumatra.


If Java get 20 years as "it" and 20 years as "legacy", then
that would actually be more than OK.

Things evolve and sometimes it is better to start with a
blank sheet of paper.

64 bit array indexes, functions as first class type, bigint and
bigdecimal as language types etc..

Arne
 
Reply With Quote
 
 
 
 
Arne Vajhj
Guest
Posts: n/a
 
      07-10-2010
On 09-07-2010 19:56, Roedy Green wrote:
> On Fri, 09 Jul 2010 08:49:27 -0400, Eric Sosman
> <(E-Mail Removed)> wrote, quoted or indirectly quoted
> someone who said :
>>> Arrays can only be indexed by ints, not longs. Even if they were,
>>> even Bill Gates could not afford enough RAM for an array of bytes, one
>>> for each possible long.

>>
>> True, but not especially relevant: You'll hit the int limit long
>> before running out of dollars. $50US will buy more RAM than a Java
>> byte[] can use.

>
> I don't think our two posts conflict.


They don't if we assume that your post was irrelevant for the
thread.

Arne

 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      07-10-2010
On 09-07-2010 12:13, Peter Duniho wrote:
> RedGrittyBrick wrote:
>> On 09/07/2010 02:30, Arne Vajhøj wrote:
>>> On 08-07-2010 21:02, Boris Punk wrote:
>>>> "Arne Vajhøj"<(E-Mail Removed)> wrote:
>>>>> On 08-07-2010 18:22, Boris Punk wrote:
>>>>>> Is there no BigList/BigHash in Java?
>>>>>
>>>>> No.
>>>>>
>>>>> But You can have a List<List<X>> which can then
>>>>> store 4*10^18 X'es.
>>>>
>>>> Please explain...
>>>
>>> You have a list with up to 2*10^9 elements of type List<X> that

>>
>> Thunderbird displays that rather nicely.
>>
>>> each can contain up to 2^10^9 elements of type X.

>>
>> But that looks pretty weird. ITYM 2*10^9
>>
>> Which demonstrates that attention to typography by Thunderbird's
>> programmers helps proof-reading by it's users

>
> Only after the fact though. Unfortunately, it doesn't provide
> composition-time formatting like that.
>
> And after all that, I'm still not clear on why Arne's figures are in
> base-10. AFAIK, you can fit a full 2^31-1 (Integer.MAX_VALUE) elements
> in a list. So you could fit (2^31-1)^2 elements in a list of lists.
> Possibly he's just using base-10 because the numbers are easier to deal
> with when rounded like that?


I considered powers of 10 more readable than powers of 2.

Arne
 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      07-10-2010


"Arne Vajhj" <(E-Mail Removed)> wrote in message
news:4c37bcf4$0$282$(E-Mail Removed)...
> On 09-07-2010 02:07, Mike Schilling wrote:
>> "Arne Vajhj" <(E-Mail Removed)> wrote in message
>> news:4c366580$0$280$(E-Mail Removed)...
>>> On 08-07-2010 17:15, Lew wrote:
>>>> From the JLS, which I strongly urge you to study:
>>>
>>> Unless the poster has a solid programming experience,
>>> then the JLS may not be the best to study.
>>>
>>> Sure it is by definition correct,

>>
>> mod typos and misstatements, of course.

>
> What counts: "what is written in the spec" or "what
> should have been written in the spec" ?


When the implementations all match the latter, then the latter counts.
Honestly, the JLS isn't the Bible, and we don't have to pretend that the sun
goes around the earth.

 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      07-10-2010


"Eric Sosman" <(E-Mail Removed)> wrote in message
news:i173u6$vhi$(E-Mail Removed)-september.org...

>
> In ten years, we'll all have jobs converting "legacy Java code"
> to Sumatra.


"It was a class which is associated with the giant array of Sumatra, a
construct for which the world is not yet prepared."

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      07-10-2010
Arne Vajhøj wrote:
>>>> Unless the poster has a solid programming experience,
>>>> then the JLS may not be the best to study.
>>>>
>>>> Sure it is by definition correct,


Mike Schilling wrote:
>>> mod typos and misstatements, of course.


Arne Vajhøj wrote:
>> What counts: "what is written in the spec" or "what
>> should have been written in the spec" ?


Mike Schilling wrote:
> When the implementations all match the latter, then the latter counts.
> Honestly, the JLS isn't the Bible, and we don't have to pretend that the
> sun goes around the earth.


Actually it's just as valid to say the Sun revolves around the Earth as the
other way, it's just that the math is so much easier heliocentrically.

There was a young lady from Bright
who traveled faster than light.
She set out one day
in a relative way
and returned the previous night.

--
Lew
 
Reply With Quote
 
ClassCastException
Guest
Posts: n/a
 
      07-10-2010
On Fri, 09 Jul 2010 09:13:40 -0700, Peter Duniho wrote:

> RedGrittyBrick wrote:
>> On 09/07/2010 02:30, Arne Vajhøj wrote:
>>> On 08-07-2010 21:02, Boris Punk wrote:
>>>> "Arne Vajhøj"<(E-Mail Removed)> wrote:
>>>>> On 08-07-2010 18:22, Boris Punk wrote:
>>>>>> Is there no BigList/BigHash in Java?
>>>>>
>>>>> No.
>>>>>
>>>>> But You can have a List<List<X>> which can then store 4*10^18 X'es.
>>>>
>>>> Please explain...
>>>
>>> You have a list with up to 2*10^9 elements of type List<X> that

>>
>> Thunderbird displays that rather nicely.
>>
>>> each can contain up to 2^10^9 elements of type X.

>>
>> But that looks pretty weird. ITYM 2*10^9
>>
>> Which demonstrates that attention to typography by Thunderbird's
>> programmers helps proof-reading by it's users

>
> Only after the fact though. Unfortunately, it doesn't provide
> composition-time formatting like that.
>
> And after all that, I'm still not clear on why Arne's figures are in
> base-10. AFAIK, you can fit a full 2^31-1 (Integer.MAX_VALUE) elements
> in a list. So you could fit (2^31-1)^2 elements in a list of lists.


Which would be 2^62 - 2^32 + 1.
 
Reply With Quote
 
ClassCastException
Guest
Posts: n/a
 
      07-10-2010
On Fri, 09 Jul 2010 16:54:53 -0400, Eric Sosman wrote:

> On 7/9/2010 4:06 PM, Daniel Pitts wrote:
>> interface Hasher<T> {
>> long hash(T value);
>> }

>
> A 64-bit hashCode() would be of little use until you got to
> more than 2^32 hash buckets. Just saying.


Gets us back to the original topic.

>> interface Equivalence<T> {
>> boolean equal(T left, T right);
>> }

>
> I don't get it: Why not just use equals()? I guess a class
> could choose not to implement Equivalence at all (and thus make itself
> unusable in whatever framework relies on Equivalence), but is that an
> advantage? Also, you could get a compile-time error instead of a
> run-time `false' for trying to call equal() on references of dissimilar
> classes; again, where's the benefit?
>
>> Then, all the appropriate Collection code could use those interfaces.
>> There should also be the obvious default implementations.

>
> It might be helpful to give some examples of the "appropriate"
> uses, and of the "obvious" defaults. For example, how does a HashMap
> make use of a key that implements Hasher? Does it reflect on each key
> its given and make a run-time choice between using hash() and
> hashCode()? I don't get it ...


Note that those interfaces specify methods with an "extra" parameter
each. They're like Comparator versus compareTo/Comparable.

The purpose is clear: so a HashMap could be given, optionally, a
Hasher<K> to use in place of the keys' own hashCode methods and an
Equivalence<K> to use in place of the keys' own equals methods.

One obvious benefit is that you get rid of IdentityHashMap by folding
that functionality into plain HashMap. Instead of a separate class, you'd
get an identity hash map with

new HashMap<K,V>(new Hasher<K>() {
public long hash (K x) {
return System.identityHashCode(x);
}
}, new Equivalence<K>() {
public boolean equal (K x, K y) {
return x == y;
}
};

or with canned instances of IdentityHasher and IdentityEquivalence
provided by the library.

With this, you would also be able to get identity WeakHashMaps and the
like; by separating the "how strong is the reference" aspect into one
class and the "how is identity decided" aspect into another, you avoid a
combinatorial explosion and possible lacunae of capability (right now we
have no WeakIdentityHashMap, in particular).

You'd also be able to reduce some of the clumsier uses of HashMap to
HashSet. Picture a

class Record {
public final int id;
public final String name;
public final String address;
}

with the obvious equality semantics (all fields equal) and constructor
added.

Now throw in an Equivalence and a Hasher that use only the record's id
field.

So maybe you keep a change log for an individual person as a
List<Record>, chronological:

id 0001
name Jane Herman
address 1600 Pennsylvania Avenue

id 0001
name Jane Herman
address 18 Wisteria Lane

id 0001
name Jane Thurston
address 18 Wisteria Lane

OK, so she got voted out of office, then got married, or something like
that.

Of course you might want to throw a jumble of records in a Set and have
different ones of the above count as different.

But you might also want a record of the current state of affairs. Given a
HashSet implementation that can use a supplied Hasher and Equivalence the
way TreeSet can use an externally-supplied Comparator, and that also has
the semantics that adding an element that equals an already-present
element replaces that element with the new one, you can update the 0001
record simply by putting a more recent one into this set -- if it already
has a 0001 record, the provided Hasher and Equivalence will lead to the
new one replacing that one.

So in some contexts you can treat records identically only if they're
actually identical; in others if they have the same id; all without
monkeying with an explicit id-to-record HashMap or suchlike.

Another way to achieve this last, though, is to have a KeyExtractor<T>
interface that you implement in this case to return the id field of a
Record and a HashSet implementation that uses the object itself as the
key in its internal HashMap if no KeyExtractor is specified during
construction, and uses the supplied KeyExtractor otherwise. This is
actually closer to the conceptual truth of what you're doing in a case
like this: keying on the id field in a particular HashSet. The
implementation would be something like

public class HashSet<T> {
private HashMap<Object,T> data = new HashMap<Object,T>();
private KeyExtractor<T> ke = new KeyExtractor<T>() {
public Object getKey (T val) {
return val;
}
}

...

public T put (T newElem) {
Object key = ke.getKey(newElem);
T oldElem = data.get(key);
data.put(key, newElem);
return oldElem;
}
}

whereas the Hasher/Equivalence version would just pass the Hasher and
Equivalence to the HashMap constructor when initializing Data and not
have the key local in put, just newElem.

The really interesting thing is that we don't really need to wait for any
hypothetical future Sun (Oracle?) update to do some of this; KeyExtractor
and the above variation of HashSet can be implemented now, perhaps
calling the latter RecordMap instead as it acts as a map from key fields
of records of some sort to whole records, in the typical case, and in
fact you probably do also want to do lookups of whole records by just the
keys. And you might sometimes want to hold the records via weak or soft
references, e.g. to make it a cache. In that case you want to allow
specifying two more things, a type of reference to use (enum
ReferenceType {STRONG; SOFT; WEAK;} with default STRONG) and an optional
ExpensiveGetter that defaults to return null but can be replaced with one
whose expensiveGet() does something like, say, retrieve disk records.
Then get() calls expensiveGet() on not-found and if expensiveGet()
doesn't throw or return null, does a put() before returning the result.
You can throw in another type parameter, too:

public class RecordMap <K,V,E> {
private ExpensiveGetter<K,V,E> eg = new ExpensiveGetter<K,V,E>() {
public V expensiveGet (K key) throws E {
return null;
}
}

private HashMap<K,Object> data = new HashMap<K,Object>();

public enum ReferenceType {
STRONG {
public Object wrap (Object o) {
return o;
}
};
SOFT {
public Object wrap (Object o) {
return new SoftReference(o);
}
};
WEAK {
public Object wrap (Object o) {
return new WeakReference(o);
}
};
public abstract Object wrap (Object o);
}

private ReferenceType referenceType = ReferenceType.STRONG;

...

@SuppressWarnings("unchecked")
public V get (K key) throws E {
Object result = data.get(key);
if (result instanceof Reference) result = result.get();
if (result != null) return (V)result;
result = eg.expensiveGet(key);
if (result == null) return null;
put(key, result);
return (V)result;
}

public void put (K key, V val) {
data.put(key, referenceType.wrap(val);
}
}

This is a bit messy but it's just a quick draft. It doesn't actually
implement Map because it doesn't quite fit the Map contract in a few
places (and making it do so would be difficult, particularly since get
seems to have to be able to throw exceptions). You might want to change
ExpensiveGet to a more general BackingSource that provides both get and
put methods; puts write through to the real backing store whenever
performed as well as writing to the RecordMap in memory, making a
RecordMap with a non-default BackingSource a cache backed by something in
a two-way fashion.

I may be a bit rusty on the syntax of giving enum constants behavior,
too. Clearly in this case that's the right thing to do, from an OO
perspective, rather than having a switch clause in the put method that
could get out of synch if someone decided to add PHANTOM to the thing for
whatever reason or a future JDK added more Reference types that
influenced GC policy in as-yet-unforeseen ways.
 
Reply With Quote
 
ClassCastException
Guest
Posts: n/a
 
      07-10-2010
On Fri, 09 Jul 2010 21:53:10 -0400, Arne Vajhøj wrote:

> On 09-07-2010 10:31, Patricia Shanahan wrote:
>> On 7/9/2010 5:15 AM, Eric Sosman wrote:
>>> On 7/8/2010 9:11 PM, Patricia Shanahan wrote:
>>>> Arne Vajhøj wrote:
>>>>> On 08-07-2010 17:35, Boris Punk wrote:
>>>>>> Integer.MAX_VALUE = 2147483647
>>>>>>
>>>>>> I might need more items than that. I probably won't, but it's nice
>>>>>> to have
>>>>>> extensibility.
>>>>>
>>>>> It is a lot of data.
>>>>>
>>>>> I think you should assume YAGNI.
>>>>
>>>> Historically, each memory size has gone through a sequence of stages:
>>>>
>>>> 1. Nobody will ever need more than X bytes.
>>>>
>>>> 2. Some people do need to run multiple jobs that need a total of more
>>>> than X bytes, but no one job could possibly need that much.
>>>>
>>>> 3. Some jobs do need more than X bytes, but no one data structure
>>>> could possibly need that much.
>>>>
>>>> 4. Some data structures do need more than X bytes.
>>>>
>>>> Any particular reason to believe 32 bit addressing will stick at
>>>> stage 3, and not follow the normal progression to stage 4?
>>>
>>> None. But Java's int isn't going to grow wider, nor will the type of
>>> an array's .length suddenly become non-int; too much code would break.
>>> When Java reaches the 31-bit wall, I doubt it will find any convenient
>>> door; Java's descendants may pass through, but I think Java will
>>> remain stuck on this side.
>>>
>>> In ten years, we'll all have jobs converting "legacy Java code" to
>>> Sumatra.

>>
>> I don't think the future for Java is anywhere near as bleak as you
>> paint it.
>>
>> The whole collections issue could be handled by creating a parallel
>> hierarchy based on java.util.long_collections (or something similar for
>> those who don't like separating words in package names). It would
>> replicate the class names in the java.util hierarchy, but with long
>> replacing int wherever necessary to remove the size limits. It could be
>> implemented, using arrays of arrays where necessary, without any JVM
>> changes.
>>
>> To migrate a program to the new collections one would first change the
>> import statements to pick up the new packages, and then review all int
>> declarations to see if they should be long. Many of the ones that need
>> changing would show up as errors.

>
> Collections is certainly solvable.
>
>> Arrays are a worse problem, requiring JVM changes. The size field
>> associated with an array would have to be long. There would also need
>> to be a new "field" longLength. Attempts to use arrayRef.length for an
>> array with more that Integer.MAX_VALUE elements would throw an
>> exception. arrayRef.length would continue to work for small arrays for
>> backwards compatibility.
>>
>> I suspect Eclipse would have "Source -> Long Structures" soon after the
>> first release supporting this, and long before most programs would need
>> to migrate.

>
> It is not a perfect solution.
>
> When calling a library some arrays would have to be marked as
> @SmallArray to indicate that you can not call with a big array, because
> the method calls length.


IMO this is barking up the wrong tree. Changing existing arrays to use
long lengths is going to break a ton of stuff and be very difficult to
pull off without a LOT of headaches.

So what should be done is to introduce a parallel *new* data structure
that is a long array and is treated as a different family of types to the
existing array types. You'd createe one by using a long constant in the
square brackets: new Foo[29954683548976828345678L]. If you wanted to you
could make a "long" array new Foo [3L] that would be a long array in
terms of type compatibility while not actually being long; so you could
mix arrays of shorter-than-2^31 and longer arrays in the same code if you
had to. The Arrays class would have long-array versions of its methods
and methods to convert short to long arrays.

The trickier part is that we'd also need a bunch of new type names; Foo[]
would have to remain "a short array of Foo" so we'd need to allow, say,
Foo[L] or some such notation to mean "a long array of Foo" when an array
type needed to be specified. (The Arrays method signatures then tend to
have type parameters and argument overloads for T[] and T[L], and of
course T[L] makeLongArray <T> (T[] shortArray).)

The supersized BigCollection classes could be made before these changes,
using hierarchical array structures under the hood, and later have their
innards retrofit to use long arrays.

As for numerics using arrays, if you really need fast numerics you might
want to contemplate simply going native, as long as you wrap whole
lengthy computations in JNI rather than each little individual step;
otherwise the overhead of going down and back up through JNI all the time
will ruin performance. The downside is you lose easy portability. At some
point Java needs a good numerics library that has many cross-platform
versions and takes advantage of SIMD, pipelining, and other CPU-
enhancement tricks on the appropriate architectures. Probably this means
a kind of added language and compilers that can make a DLL implementing
JNI methods plus a .class for you out of source code with Java method
declarations that contain expressions in a subset of FORTRAN, or
something of the sort, or even just a "native math enabled compiler" that
will turn Java methods in your source code into native methods that meet
certain criteria involving basically only doing arithmetic on primitives.

Actually that might be too limiting. Really you'd need some sort of
metacompiler or templating facility. Situations like that make me want to
use Lisp macros instead of just Java, so I can have higher-level source
code that still converts into primitive-arithmetic code after
macroexpansion and can then be eligible to become optimized native math
code.

Actually, what's *really* needed is for the JVM JIT to really take
advantage of the host CPU's numerics features. The problem is that by the
time the JIT is optimizing assembly any large-scale features of the
problem (e.g., that it's doing vector sums) that could inform such
optimizations have dissolved into a low-level representation where it
can't see the forest for the trees.

Nonetheless I've seen impressive performance from JITted code on -server
class machines, especially if the source was Clojure with macros used to
reduce high-level concepts at compile time into a tight arithmetic loop
or whatever. The results are comparable to a basic stab at coding the
arithmetic loop in assembly, e.g. 7-10ns per iteration for a few fpu
mults and adds with some compare-and-tests on a GHz CPU, the kind of
speed you'd get if the loop compiled down to just the obvious FPU
instructions with fairly efficient register use but no fancy SIMD/MMX/
etc. feature use or GPU use. Java gets the same speed with the FP loop
coded in Java in the obvious way; what macros get you is the ability to
have parameters in that loop that affect its structure in various ways
and if they're set at compile time the loop's as fast as if it were
simple. A good javac implementation might get you equivalent performance
if ifs that have compile-time-constant false expressions compile away to
just the else clause or nothing and ones with compile-time-constant true
expressions become just the then clause or nothing. With Lisp eval and
JIT, though, you get the same even if some parts of the loop aren't known
until runtime, which AFAICT is pretty much impossible in plain Java.

OK, rambling a bit. The upshot is that the JIT is the place that applies
the most leverage to optimizing numerics, since it could do so across all
JVM hosted languages and not just Java. The language might better support
this if, among other things, it supported long arrays. Floating-point
types larger than double and more efficient bignum types would also go a
long way. One problem with making a more efficient bignum type is that
there's no way in Java to check if an integer operation left the carry
bit set in the CPU, so you have to make do with 31- or 63-bit chunks in
your bignums and explicit tests of the high bit everywhere. The latter's
the bigger performance killer; if Java had an "if carry" you could use
immediately following an integer arithmetic expression, you could do
things like

newLow = low1 + low2;
if-carry {
newHigh = high1 + high2 + 1;
} else
newHigh = high1 + high2;
}

with the compiler arranging it that low1 + low2 is done and stored in
some register; then the carry bit is tested; etc.

Better yet,

newLow = low1 + low2;
newHigh = high1 + high2 + carry;

would be nice! This could compile and JIT into very efficient assembly on
architectures that provide explicit add-without-first-clearing-carry
instructions as well as ordinary adds, and similarly for other arithmetic
operations, providing all the building blocks to assemble bignums right
on the chip.

Of course, the most efficient bignum implementation will also depend on
the largest one-cycle-arithmetic word size the CPU supports. Maybe it's
best if bignums are special-case library classes instead. The existing
BigInteger and BigDecimal that are base-10 would be kept for
compatibility, and new BigInt and BigFloat classes added that are binary
and maximum-speed, with a group of architecture-selected native method
implementations provided with them and the one appropriate to the current
host hardware selected on the fly by the JIT the first time a bignum
native method got called.

Of course, then this new functionality should be made available to all
JNI users: the ability to supply several versions of the native code for
different architectures, labeled in some manner, for the JIT to select.
When code that calls the native method runs the first time, the most
appropriate one will be selected and the calling method will immediately
be JITted to an optimized assembly form that calls the specific,
appropriate native method for the CPU, so subsequent calls to that
calling method will not have to repeat the test-and-selection process (on
the presumption, valid for the foreseeable future, that the CPU
architecture will not change in the middle of a single program run -- but
if, in the future, program runs can be hibernated and then resumed on
changed hardware, all JIT caches will have to be invalidated on such
occasions anyway).

So, final conclusion:
* Add a parallel collection library that allows long-indexed collections
(size, indexing methods, etc. return long). Add RandomAccessIterator to
existing Iterator and ListIterator that allows indexed-sized forward and
backward jumps. Add a RandomAccessList interface that ArrayList
implements and that provides a RandomAccessIterator. Let the new
collection interfaces add an exception type parameter that can be
thrown by the methods, so specific implementations can be backed by disk
files and throw IOException or by databases and throw SQLException,
while the basic in-memory ones would have this type parameter set to
RuntimeException to indicate no additional checked exceptions get
thrown. RandomAccessFile would be retrofit to implement
RandomAccessList<byte>.
* Long arrays would be a good idea, but add them as new, parallel data
structures to the existing arrays so as not to add too many
compatibility headaches. The supersized collection implementations would
be internally reworked to exploit the new long arrays to make them more
efficient.
* JIT should be improved to optimize the use of long arrays.
* JIT should be improved to allow native method calls whose callers get
JITted to start calling an architecture-optimized version of the native
method selected at JIT time from among several provided alternatives
based on the actual host hardware at JIT time.
* JNI toolkit should provide a way to generate such alternative version
sets of native methods.
* JIT should invalidate code caches on any session-save-and-restore on any
future occasion that adds such a capability to JVMs. Just save the
session with the cache empty, or else save hardware info with session
and invalidate if CPU arch is changed on restore.
* BigInt and BigFloat should be added to standard library, with efficient
multi-architecture native method alternative-sets for the major
arithmetic operations and specifyable binary precision in bits. (The
actual precision will be the next larger multiple of N bits, with N
usually either 32 or 64. You ask for a minimum precision and you get
the most efficient precision that's no lower.) Possibly add BigFixed, a
fixed-point non-integer type. BigInteger and BigDecimal don't change
from their present base-10 forms, again to avoid compatibility problems.
* Possibly add support for arrays that store contiguous blocks of records
of dissimilar primitive types, also to aid numerics. E.g. an array of
float float float int, float float float int blocks that gets stored as
a contiguous memory block. This might be implemented by adding a
primitiverecord class type to go along with class, interface, and enum,
which has pass-by-value semantics and can only contain primitive,
primitive array, and primitiverecord instance members. A
primitiverecord type is not a reference type! And it cannot contain any
as instance members! Perhaps it shouldn't be allowed to have instance
methods or constructors, either; all fields public and zeroed at
instance creation. Arrays of a primitiverecord type store the records as
contiguous blocks. Disallow "char" and "byte" to discourage creating
imitation-legacy COBOLish code storing non-numeric data or rigid,
brittle binary file formats; allow float, double, int, long, and
possibly allow enums. Allow whatever static members.
* In the further future, possibly add a sophisticated higher-level
numerics library that uses the above.

The above changes, taken over time and in the order specified, would help
transition Java to 64-bit architectures and ever larger applications,
data sets, and machines, as well as gaining it some respectability as a
language for performing numeric calculations, overall making it better
suited for portably implementing the very large simulations that will be
increasingly important in the future in engineering, climate science, and
numerous other fields of endeavor.
 
Reply With Quote
 
ClassCastException
Guest
Posts: n/a
 
      07-10-2010
On Fri, 09 Jul 2010 21:57:23 -0400, Arne Vajhøj wrote:

> On 09-07-2010 08:15, Eric Sosman wrote:
>> On 7/8/2010 9:11 PM, Patricia Shanahan wrote:
>>> Arne Vajhøj wrote:
>>>> On 08-07-2010 17:35, Boris Punk wrote:
>>>>> Integer.MAX_VALUE = 2147483647
>>>>>
>>>>> I might need more items than that. I probably won't, but it's nice
>>>>> to have
>>>>> extensibility.
>>>>
>>>> It is a lot of data.
>>>>
>>>> I think you should assume YAGNI.
>>>
>>>
>>> Historically, each memory size has gone through a sequence of stages:
>>>
>>> 1. Nobody will ever need more than X bytes.
>>>
>>> 2. Some people do need to run multiple jobs that need a total of more
>>> than X bytes, but no one job could possibly need that much.
>>>
>>> 3. Some jobs do need more than X bytes, but no one data structure
>>> could possibly need that much.
>>>
>>> 4. Some data structures do need more than X bytes.
>>>
>>> Any particular reason to believe 32 bit addressing will stick at stage
>>> 3, and not follow the normal progression to stage 4?

>>
>> None. But Java's int isn't going to grow wider, nor will the type of an
>> array's .length suddenly become non-int; too much code would break.
>> When Java reaches the 31-bit wall, I doubt it will find any convenient
>> door; Java's descendants may pass through, but I think Java will remain
>> stuck on this side.
>>
>> In ten years, we'll all have jobs converting "legacy Java code" to
>> Sumatra.

>
> If Java get 20 years as "it" and 20 years as "legacy", then that would
> actually be more than OK.
>
> Things evolve and sometimes it is better to start with a blank sheet of
> paper.
>
> 64 bit array indexes, functions as first class type, bigint and
> bigdecimal as language types etc..


Clojure has all of this already except 64 bit array indexes and runs on
the JVM.

Clojure doesn't even have arrays, though, unless you drop down to Java to
use Java's arrays. Clojure's collections are built on Java's arrays and
collections, so some limits might start kicking in when you got to 2^32
elements; I'm not sure how they behave if they get that big.

A *real* future-proof language would, of course, have bigint array
indexes.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
Use of Long and Long Long Bart C C Programming 27 01-15-2008 05:27 AM
long long and long Mathieu Dutour C Programming 4 07-24-2007 11:15 AM
unsigned long long int to long double Daniel Rudy C Programming 5 09-20-2005 02:37 AM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments