Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31977 > unrolled thread
| Started by | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| First post | 2015-07-10 11:52 +0000 |
| Last post | 2015-07-10 18:10 +0000 |
| Articles | 20 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
[JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 11:52 +0000
Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-10 08:02 -0400
Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 12:58 +0000
Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-10 09:45 -0400
Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 14:19 +0000
Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-10 20:19 +0000
Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-10 16:43 -0400
Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-10 22:24 +0000
Re: [JLS] new long[0][ -1 ] Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-11 07:33 -0400
Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 21:17 +0000
Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-10 22:29 +0000
Re: [JLS] new long[0][ -1 ] Arne Vajhøj <arne@vajhoej.dk> - 2015-07-27 22:10 -0400
Re: [JLS] new long[0][ -1 ] leif.roar@dimnakorr.com - 2015-07-28 01:53 -0500
Re: [JLS] new long[0][ -1 ] Arne Vajhøj <arne@vajhoej.dk> - 2015-07-28 19:13 -0400
Re: [JLS] new long[0][ -1 ] leif.roar@dimnakorr.com - 2015-07-28 21:50 -0500
Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-28 11:13 +0000
Re: [JLS] new long[0][ -1 ] Arne Vajhøj <arne@vajhoej.dk> - 2015-07-31 19:41 -0400
Re: [JLS] new long[0][ -1 ] Martin Gregorie <martin@address-in-sig.invalid> - 2015-08-01 10:23 +0000
Re: [JLS] new long[0][ -1 ] Joerg Meier <joergmmeier@arcor.de> - 2015-07-10 17:07 +0200
Re: [JLS] new long[0][ -1 ] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-07-10 18:10 +0000
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2015-07-10 11:52 +0000 |
| Subject | [JLS] new long[0][ -1 ] |
| Message-ID | <slrnmpvci8.uoi.avl@login.logic.tuwien.ac.at> |
I've had a look at the JLS to find out about the more or less special case of a 2-dimensional array, whose first(outer) dimension is 0, but I didn't find any extra mention of that case. From what I read, it would evaluate *all* the dimensions, then check if any of them is negative. But if first dimension is 0, then the loop shown in the "equivalent as"- code sample would not get its body run even once, so actually it wouldn't even notice if any of the further dimensions was negative. What would be an accurate *purely JLS-based* prediction for new long[0][-1] (not caring about actual existing JVM implementations) ? PS: this is not a real problem for me, just curiosity.
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-07-10 08:02 -0400 |
| Message-ID | <mnoc71$jah$1@dont-email.me> |
| In reply to | #31977 |
On 7/10/2015 7:52 AM, Andreas Leitgeb wrote:
> I've had a look at the JLS to find out about the more or less special
> case of a 2-dimensional array, whose first(outer) dimension is 0, but
> I didn't find any extra mention of that case.
>
> From what I read, it would evaluate *all* the dimensions, then check
> if any of them is negative.
>
> But if first dimension is 0, then the loop shown in the "equivalent as"-
> code sample would not get its body run even once, so actually it wouldn't
> even notice if any of the further dimensions was negative.
>
> What would be an accurate *purely JLS-based* prediction for
> new long[0][-1]
> (not caring about actual existing JVM implementations) ?
Intriguing question, but easily answered. 15.10.2, second
bullet, second sub-bullet:
"Next, the values of the dimension expressions are checked.
If the value of any DimExpr expression is less than zero,
then a NegativeArraySizeException is thrown."
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2015-07-10 12:58 +0000 |
| Message-ID | <slrnmpvgdg.uoi.avl@login.logic.tuwien.ac.at> |
| In reply to | #31978 |
Eric Sosman <esosman@comcast-dot-net.invalid> wrote: > On 7/10/2015 7:52 AM, Andreas Leitgeb wrote: >> I've had a look at the JLS to find out about the more or less special >> case of a 2-dimensional array, whose first(outer) dimension is 0, but >> I didn't find any extra mention of that case. >> >> From what I read, it would evaluate *all* the dimensions, then check >> if any of them is negative. >> >> But if first dimension is 0, then the loop shown in the "equivalent as"- >> code sample would not get its body run even once, so actually it wouldn't >> even notice if any of the further dimensions was negative. >> >> What would be an accurate *purely JLS-based* prediction for >> new long[0][-1] >> (not caring about actual existing JVM implementations) ? > > Intriguing question, but easily answered. 15.10.2, second > bullet, second sub-bullet: > > "Next, the values of the dimension expressions are checked. > If the value of any DimExpr expression is less than zero, > then a NegativeArraySizeException is thrown." My mistake was to generalize the first example in 15.10.1-2 . On second thought, the equivalence in the example-block is correct. It just cannot be generalized from dimensions 3,3 to "any" (like 0,-1), as for dims 0,-1 the compact form has to throw a NASE, while the alternative code doesn't. Thanks. Knot in my brain dissolved. :-)
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-07-10 09:45 -0400 |
| Message-ID | <mnoi74$8pm$1@dont-email.me> |
| In reply to | #31979 |
On 7/10/2015 8:58 AM, Andreas Leitgeb wrote:
> Eric Sosman <esosman@comcast-dot-net.invalid> wrote:
>> On 7/10/2015 7:52 AM, Andreas Leitgeb wrote:
>>> I've had a look at the JLS to find out about the more or less special
>>> case of a 2-dimensional array, whose first(outer) dimension is 0, but
>>> I didn't find any extra mention of that case.
>>>
>>> From what I read, it would evaluate *all* the dimensions, then check
>>> if any of them is negative.
>>>
>>> But if first dimension is 0, then the loop shown in the "equivalent as"-
>>> code sample would not get its body run even once, so actually it wouldn't
>>> even notice if any of the further dimensions was negative.
>>>
>>> What would be an accurate *purely JLS-based* prediction for
>>> new long[0][-1]
>>> (not caring about actual existing JVM implementations) ?
>>
>> Intriguing question, but easily answered. 15.10.2, second
>> bullet, second sub-bullet:
>>
>> "Next, the values of the dimension expressions are checked.
>> If the value of any DimExpr expression is less than zero,
>> then a NegativeArraySizeException is thrown."
>
> My mistake was to generalize the first example in 15.10.1-2 .
>
> On second thought, the equivalence in the example-block is correct.
> It just cannot be generalized from dimensions 3,3 to "any" (like 0,-1),
> as for dims 0,-1 the compact form has to throw a NASE, while the
> alternative code doesn't.
>
> Thanks. Knot in my brain dissolved. :-)
You're welcome. But contemplating the uses of an array with
fewer than zero elements has tied what remains of my brain in a
knot that may not dissolve until my brain itself does ... :-)
<off-topic> What use might we make of a minus-sized array?
Perhaps it could model the old joke about a biologist, an engineer,
and a mathematician at a sidewalk cafe. They see two people enter a
building across the street, and a little later three people emerge.
"They have reproduced," says the biologist. "Observational error,"
says the engineer. And the mathematician observes "If somebody now
goes inside, the building will be empty." </off-topic>
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2015-07-10 14:19 +0000 |
| Message-ID | <slrnmpvl62.uoi.avl@login.logic.tuwien.ac.at> |
| In reply to | #31980 |
Eric Sosman <esosman@comcast-dot-net.invalid> wrote: > You're welcome. But contemplating the uses of an array with > fewer than zero elements has tied what remains of my brain in a > knot that may not dissolve until my brain itself does ... :-) Some class's constructor gets passed two ints meaning width and height of some rectangular grid. Currently, the only argument-sanitization is to create a two dimensional array with it. Any exceptions caused by bad arguments to "new int[ height ][ width ]" will be seen by client-code. My concern was, that a negative width might pass undetected after a zero height. As is now clear: it doesn't, so it's all fine for me. I don't care what exceptions are thrown back for bogus arguments, as long as all bogosity ends in some exception right on the spot. > <off-topic> What use might we make of a minus-sized array? > Perhaps it could model the old joke about a biologist, an engineer, > and a mathematician at a sidewalk cafe. They see two people enter a > building across the street, and a little later three people emerge. > "They have reproduced," says the biologist. "Observational error," > says the engineer. And the mathematician observes "If somebody now > goes inside, the building will be empty." </off-topic> Too bad, arrays are fixed-size, so we cannot even add elements to make it zero-sized. ;-)
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2015-07-10 20:19 +0000 |
| Message-ID | <mnp9cb$134$1@dont-email.me> |
| In reply to | #31981 |
On Fri, 10 Jul 2015 14:19:24 +0000, Andreas Leitgeb wrote: > Eric Sosman <esosman@comcast-dot-net.invalid> wrote: >> You're welcome. But contemplating the uses of an array with >> fewer than zero elements has tied what remains of my brain in a knot >> that may not dissolve until my brain itself does ... :-) > > Some class's constructor gets passed two ints meaning width and height > of some rectangular grid. Currently, the only argument-sanitization is > to create a two dimensional array with it. Any exceptions caused by bad > arguments to "new int[ height ][ width ]" will be seen by client-code. > > My concern was, that a negative width might pass undetected after a zero > height. As is now clear: it doesn't, so it's all fine for me. I don't > care what exceptions are thrown back for bogus arguments, as long as all > bogosity ends in some exception right on the spot. > >> <off-topic> What use might we make of a minus-sized array? >> Perhaps it could model the old joke about a biologist, an engineer, and >> a mathematician at a sidewalk cafe. They see two people enter a >> building across the street, and a little later three people emerge. >> "They have reproduced," says the biologist. "Observational error," says >> the engineer. And the mathematician observes "If somebody now goes >> inside, the building will be empty." </off-topic> > > Too bad, arrays are fixed-size, so we cannot even add elements to make > it zero-sized. ;-) > Two features I'd have liked to see in Java are non-zero based arrays, e.g. int temperatureOcurrences[-40:55] and flexible array bounds, e.g int samples[0:flex] Neither are new ideas, both dating from the '60s: Algol 60 had non-zero- based fixed size arrays and Algol 68 implemented both concepts: both are useful in some circumstances as is multi-dimensional array slicing (Algol 68 had that too). -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-07-10 16:43 -0400 |
| Message-ID | <mnpamb$8ap$1@dont-email.me> |
| In reply to | #31985 |
On 7/10/2015 4:19 PM, Martin Gregorie wrote:
>
> Two features I'd have liked to see in Java are non-zero based arrays, e.g.
> int temperatureOcurrences[-40:55] and flexible array bounds, e.g
> int samples[0:flex]
Would you mind elaborating on the latter? Java already has
int flex = ...;
int[] samples = new int[flex+1];
... but do you mean something different? Do you mean, perhaps,
that a subsequent assignment to `flex' would grow or shrink the
array? What output would
int flex = 5;
int[] samples = new int[flex+1];
System.out.println(samples.length);
flex = 20;
System.out.println(samples.length);
flex = -42; // NegativeArraySizeException?
System.out.println(samples.length);
generate? Would removing the `+1' change things materially?
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2015-07-10 22:24 +0000 |
| Message-ID | <mnpgml$h0u$1@dont-email.me> |
| In reply to | #31986 |
On Fri, 10 Jul 2015 16:43:06 -0400, Eric Sosman wrote:
> On 7/10/2015 4:19 PM, Martin Gregorie wrote:
>>
>> Two features I'd have liked to see in Java are non-zero based arrays,
>> e.g.
>> int temperatureOcurrences[-40:55] and flexible array bounds, e.g int
>> samples[0:flex]
>
> Would you mind elaborating on the latter? Java already has
>
> int flex = ...;
> int[] samples = new int[flex+1];
>
> ... but do you mean something different? Do you mean, perhaps,
> that a subsequent assignment to `flex' would grow or shrink the array?
>
Brief pause while I found my Algol68R User Guide (I haven't used the
language since 1977. I mean the latter, for instance the declaration
[1:0 flex] real a; declares an array with flexible bounds and initially
no elements. So I can do the following:
a := (1.0, 2.0, 3.0); and somewhat later, I might do this:
a := (0.0, 1.1, 2.2, 3.1415926, 22.0/7.0, 0.95);
Given that there are operators associated with arrays (to extract the
lower and upper bounds (you specify which dimension for a
multidimensional array, flexible (returns true if its a flexible array)
and clear (sets all elements to the 'empty value' (0 if numeric, space if
char, false of boolean) if you think of a flexible array as being similar
to the String class you'd not be wrong.
A68 was a sort of half-way house between 'classical' and OO languages:
you could overload any operator, define new operators and do the same
with data types (known as modes). For instance, you could declare a
sketch mode to hold a set of plottable modes, derive things like
rectangles, circles and scalable text from the sketch and overload the
'+' operator so it could be used to add and these to another sketch, so
you could write
circle [] c = ( list of circles );
sketch s := frame + text("My Sketch");
for i from lwb c to upb c do s += c[i];
But A68 was NOT an OO language because there was no concept of a class
and its instances. The most you could do was declare a program segment
which would normally contain a set of mode definitions and the operators
and/or procedures needed to use them. A segment was more like a C source
module than a class declaration.
as NOT an OO language
> What output would
>
> int flex = 5;
> int[] samples = new int[flex+1]; System.out.println
(samples.length);
> flex = 20; System.out.println(samples.length);
> flex = -42; // NegativeArraySizeException?
> System.out.println(samples.length);
>
You can't do that: once a flexible array is declared, you change its size
by assigning stuff to it. IIRC you could do something like:
int [] source = (1,2,3,4,5,6,7,8,9,0);
[1:0 flex] a; // an empty flexible array;
for i from lwb source to upb source do a[i] = source[i];
IOW a flexible array doesn't do much that an ArrayList can't do;
It can be very useful when you're parsing lines of text and want split it
into an array of words.
Depending on what you want to do, though getting away from zero-based
arrays is rather more useful, if only because it gets you away from
continually calculating the base offset.
HTH
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-07-11 07:33 -0400 |
| Message-ID | <mnqurs$qn5$1@dont-email.me> |
| In reply to | #31988 |
On 7/10/2015 6:24 PM, Martin Gregorie wrote:
> On Fri, 10 Jul 2015 16:43:06 -0400, Eric Sosman wrote:
>
>> On 7/10/2015 4:19 PM, Martin Gregorie wrote:
>>>
>>> Two features I'd have liked to see in Java are non-zero based arrays,
>>> e.g.
>>> int temperatureOcurrences[-40:55] and flexible array bounds, e.g int
>>> samples[0:flex]
>>
>> Would you mind elaborating on the latter? Java already has
>>
>> int flex = ...;
>> int[] samples = new int[flex+1];
>>
>> ... but do you mean something different? Do you mean, perhaps,
>> that a subsequent assignment to `flex' would grow or shrink the array?
>>
> Brief pause while I found my Algol68R User Guide (I haven't used the
> language since 1977. I mean the latter, for instance the declaration
>
> [1:0 flex] real a; declares an array with flexible bounds and initially
> no elements. So I can do the following:
>
> a := (1.0, 2.0, 3.0); and somewhat later, I might do this:
> a := (0.0, 1.1, 2.2, 3.1415926, 22.0/7.0, 0.95);
>[...]
Java can do that:
double[] a = new double[0];
a = new double[] { 1.0, 2.0, 3.0 };
a = new double[] { 0.0, 1.1, 2.2, 3.1415926, 22.0/7.0, 0.95 };
Java can't, however, do the kind of slice-'n-dice operations you
mention, and it can't escape its zero-origin requirement.
Thanks for the explanation.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2015-07-10 21:17 +0000 |
| Message-ID | <slrnmq0dm3.uoi.avl@login.logic.tuwien.ac.at> |
| In reply to | #31985 |
Martin Gregorie <martin@address-in-sig.invalid> wrote: > Two features I'd have liked to see in Java are non-zero based arrays, e.g. > int temperatureOcurrences[-40:55] and flexible array bounds, e.g > int samples[0:flex] Given that arrays are meant as internal building blocks for higher level structures, then the answer would be a custom class that would wrap an array and present an interface with custom index ranges. But as the topic is now bent towards wish lists, then I'll throw in my latest brain-fart: Arrays of non-reifiable types could be allowed with the special restriction that *such* an array would then not be castable to any other array-type. It would be the compiler, not the VM to enforce that. It might need some more fleshing out, and maybe some annotation at the declaration to avoid certain compatibility issues, but it would avoid the chasm that currently separate generics and arrays.
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2015-07-10 22:29 +0000 |
| Message-ID | <mnpgvs$h0u$2@dont-email.me> |
| In reply to | #31987 |
On Fri, 10 Jul 2015 21:17:33 +0000, Andreas Leitgeb wrote: > Martin Gregorie <martin@address-in-sig.invalid> wrote: >> Two features I'd have liked to see in Java are non-zero based arrays, >> e.g. >> int temperatureOcurrences[-40:55] and flexible array bounds, e.g int >> samples[0:flex] > Given that arrays are meant as internal building blocks for higher level > structures, then the answer would be a custom class that would wrap an > array and present an interface with custom index ranges. > Fair point: I started to realise this as I wrote the previous post. Just as an ArrayList does much of what am A68 flexible array does, you could subclass an ArrayList with a constructor argument that effectively sets the lower bound by being subtracted from, e.g. the get() index to make it zero-based. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-07-27 22:10 -0400 |
| Message-ID | <mp6ob1$vvq$1@speranza.aioe.org> |
| In reply to | #31985 |
On 7/10/2015 4:19 PM, Martin Gregorie wrote: > Two features I'd have liked to see in Java are non-zero based arrays, e.g. > int temperatureOcurrences[-40:55] and flexible array bounds, e.g > int samples[0:flex] > > Neither are new ideas, both dating from the '60s: Algol 60 had non-zero- > based fixed size arrays and Algol 68 implemented both concepts: both are > useful in some circumstances as is multi-dimensional array slicing (Algol > 68 had that too). I agree that non-zero based arrays can result in much cleaner code in some cases. But I think it has to be bundled with another feature: the use of other types than int as array indexes. I don't think that it is desirable or likely to shoehorn into Java at this time. If one want it then I suggest Ada and JGnat! :-) Arne
[toc] | [prev] | [next] | [standalone]
| From | leif.roar@dimnakorr.com |
|---|---|
| Date | 2015-07-28 01:53 -0500 |
| Message-ID | <u4SdnUQIebF3uyrInZ2dnUU78XGdnZ2d@giganews.com> |
| In reply to | #32169 |
Arne Vajhøj <arne@vajhoej.dk> wrote: > > If one want it then I suggest Ada and JGnat! > I know you're jesting, but wasn't JGnat pretty much abandoned several years ago? -- Leif Roar Moldskred
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-07-28 19:13 -0400 |
| Message-ID | <mp92bl$82h$1@speranza.aioe.org> |
| In reply to | #32177 |
On 7/28/2015 2:53 AM, leif.roar@dimnakorr.com wrote: > Arne Vajhøj <arne@vajhoej.dk> wrote: >> >> If one want it then I suggest Ada and JGnat! > > I know you're jesting, but wasn't JGnat pretty > much abandoned several years ago? ACT released last GPL version in 2013. Not that long time ago. And I were only half jesting. I like the Pascal/Modula-2/Ada languages a lot. Arne
[toc] | [prev] | [next] | [standalone]
| From | leif.roar@dimnakorr.com |
|---|---|
| Date | 2015-07-28 21:50 -0500 |
| Message-ID | <ZYydnWJ0DtcZoiXInZ2dnUU78VOdnZ2d@giganews.com> |
| In reply to | #32188 |
Arne Vajhøj <arne@vajhoej.dk> wrote: > > ACT released last GPL version in 2013. Not that long > time ago. > Huh -- that's several years after I thought they'd abandoned it due to lack of interest. I am surprised. Pleased, but surprised. > And I were only half jesting. I like the Pascal/Modula-2/Ada > languages a lot. Agreed. Ada is one of the best designed programming languages in existence. In particular its type system really is second to none. -- Leif Roar Moldskred
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2015-07-28 11:13 +0000 |
| Message-ID | <mp7o55$fr0$1@dont-email.me> |
| In reply to | #32169 |
On Mon, 27 Jul 2015 22:10:41 -0400, Arne Vajhøj wrote: > But I think it has to be bundled with another feature: the use of other > types than int as array indexes. > I suppose you're thinking of the sort of flexibility offered by awk or Perl? IME you can achieve the same in Java by using TreeMap or HashMap, the choice probably depending on whether you need ordered access to the array elements. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-07-31 19:41 -0400 |
| Message-ID | <55bc07c7$0$301$14726298@news.sunsite.dk> |
| In reply to | #32179 |
On 7/28/2015 7:13 AM, Martin Gregorie wrote: > On Mon, 27 Jul 2015 22:10:41 -0400, Arne Vajhøj wrote: >> But I think it has to be bundled with another feature: the use of other >> types than int as array indexes. >> > I suppose you're thinking of the sort of flexibility offered by awk or > Perl? No - Pascal/Modula-2/Ada style. Preferably type safe indexes like in Ada. > IME you can achieve the same in Java by using TreeMap or HashMap, > the choice probably depending on whether you need ordered access to the > array elements. I am sure that something can be constructed. But I don't think it will have the simplicity as in those other languages. Arne
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2015-08-01 10:23 +0000 |
| Message-ID | <mpi6m8$6do$4@dont-email.me> |
| In reply to | #32234 |
On Fri, 31 Jul 2015 19:41:58 -0400, Arne Vajhøj wrote: >> IME you can achieve the same in Java by using TreeMap or HashMap, >> the choice probably depending on whether you need ordered access to the >> array elements. > > I am sure that something can be constructed. But I don't think it will > have the simplicity as in those other languages. > I dunno: writing TreeMap<KeyType, MyClass> is simple enough, very explicit and rather easy to instantiate and use. I don't know Ada, but the Algol 68 equivalent is very similar: mymode[myindextype] a[-500:500]; -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2015-07-10 17:07 +0200 |
| Message-ID | <1gocmmafgwljm$.xuiw90f9wmdy$.dlg@40tude.net> |
| In reply to | #31977 |
On Fri, 10 Jul 2015 11:52:18 +0000 (UTC), Andreas Leitgeb wrote: > What would be an accurate *purely JLS-based* prediction for > new long[0][-1] > (not caring about actual existing JVM implementations) ? I predict that the above code will add an additional 8 bytes (the size of a long) to your total available memory. It has long been a poorly kept secret that if your Java app needs additional memory, you can just do new long[0][-131072] to get an additional MB. Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2015-07-10 18:10 +0000 |
| Message-ID | <slrnmq02np.uoi.avl@login.logic.tuwien.ac.at> |
| In reply to | #31982 |
Joerg Meier <joergmmeier@arcor.de> wrote:
> On Fri, 10 Jul 2015 11:52:18 +0000 (UTC), Andreas Leitgeb wrote:
>> What would be an accurate *purely JLS-based* prediction for
>> new long[0][-1]
>> (not caring about actual existing JVM implementations) ?
>
> I predict that the above code will add an additional 8 bytes (the size of a
> long) to your total available memory. It has long been a poorly kept secret
> that if your Java app needs additional memory, you can just do new
> long[0][-131072] to get an additional MB.
Amazing!
I tried this:
class Test {
public static void main(String[] args) {
try {
boolean flag = false; // true;
long test[][];
if (flag) {
test = new long[0][Integer.MIN_VALUE];
}
test = new long[1][Integer.MAX_VALUE];
} catch (Throwable t) { /* ignore */ }
}
}
and ran it once with flag = false, then with flag = true, and guess what?
With the flag on false, memory consumption went up to about 16GB, whereas
with flag true it hardly used any memory at all!
Finally, I know how these memory-multiplier Apps work, just not
why they need access to all my accounts... ;-)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web