Re: How to tie
Abble wrote:
On Dec 31, 10:52 am, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
Abble wrote:
If the goal is to interpose your own code on array accesses
in Java, I think you're out of luck: Array accesses use built-in
opcodes of the Java Virtual Machine, and there's no provision for
you to insert your own code into the JVM. (Hard to see how the
security and integrity models could permit such a thing, anyhow.)
Perhaps it's time to take a step back: What kind of code do
you want to interpose, and for what purpose? Perhaps the cat
can be skinned some other way.
Thanks Eric,
What I'd like to do is tie a Java array to a a sparse array
database of sorts. These arrays might be really sparse, or maybe
dimensioned far in excess of any RAM or even VM. It sure would be
nice to present the appearance of an array[million,million,million].
I can do this in FORTRAN (by trapping segment violations), I can do
this in C (with macros), I can do it in C++, I think, by overloading
operators. I can do it in Delphi Pascal, same as in FORTRAN.
Sure would be nice to do it in Java too.
I understand this is likely to a bit of a stretch in any language
that is security-conscious.
It's been many years since I used FORTRAN, but the idea
of using a normal array reference and then trapping segment
violations strikes me as both slow and fragile. "Slow" because
practically every reference will produce a trap that needs to
be untangled and handled (didn't you say speed was an issue?),
and "fragile" because a bug somewhere else in the program might
get mis-routed to your trap handler with unhappy consequences.
Also, there's no hope at all of getting it to work for arrays
"far in excess of any [...] VM:" what if two sets of indices
wrap around to the same VM address, or to some unrelated but
valid address in your program?
C's preprocessor macros just get you a notational sugar-
coating, at the cost of using FORTRAN-esque array indexing
A(i,j,k) instead of C's own A[i][j][k]. You still wind up with
a function call.
I'll leave C++ for someone else; I've avoided it thus far
and would just as soon continue to do so.
Pascal is another language I haven't used in donkey's years,
but when I used it there were no facilities for interjecting one's
own code into array operations nor for trapping address faults.
I never used this Delphi dialect you mention, but if it allows
the same dodge you're contemplating for FORTRAN then I suspect
it has the same drawbacks.
What you seem to be after is the notational convenience of
an A(i,j,k) "array" reference. If you really really really must
have it and cannot stand writing A.get(i,j,k) and A.put(i,j,k,val),
I suggest you write your code in a Java-ish language that gets
transformed into actual Java by running it through a preprocessing
program of some kind:
$A(i,j,k) = $A(i,j,k) + $B(i,j) * $C(j,k);
might become
A.put(i,j,k, A.get(i,j,k) + B.get(i,j) + C.get(j,k));
It all comes down to what price you're willing to pay for the
convenience.
--
Eric Sosman
esosman@ieee-dot-org.invalid