Which is to say: exactly as much as your machine can handle (note the formula 
below also defines the limits of memory pointers on modern architectures). 

Which should also tell you that the max number of items depends on the size (in 
memory) of 1 item.  The smallest J item is one byte (a literal atom), so you 
could have 4 billion of those on a 32 bit machine (modulo OS taxes).  But if 
your items were, say, 4-byte integers, you'd max out at 1 billion.  And if your 
items were tuples of 3 integers (R,G,B pixels, for example) you'd top out at 
~300 million, etc.


Of course, J also supports sparse arrays, which have the same theoretical limit 
(2^n etc) but much higher practical limits, as they only store the relevant 
parts of arrays (of course, if all the items of your array are relevant, you're 
back to the same memory limit).  

Why do you ask?

-Dan

PS: Roger's formula refers to the limit of a single dimension of a J array (the 
number of "items", as opposed to "atoms").  But J arrays are multidimensional, 
and each dimension could (in theory) have that many items, and of course the 
array's total volume is the product of all its dimensions.  The max # of 
dimensions for a J array also shares Roger's limit, so the max shape J's 
internals can handle is 

   shape =. $~ _1+2^n-1 

And correspondingly its volume would be */shape which is shape^shape or about 
2^(n-1)^2 atoms.  Which of course no machine can handle.  But it does let you 
play silly games like carrying payload data around in the shape of an (empty) 
array :)

And while we're discussing theory, it's worth pointing out that the 
specification of J (the Dictionary) imposes no limits on array size.  So in 
theory, a different implementation of J could have arrays that stretched back 
onto disk (like a RDBMS), or across mutliple disks, or across multiple 
networked machines, or across the globe.... 

The notation wouldn't change.  Just the implementation.



Please excuse typos; composed on a handheld device.

-----Original Message-----
From: Roger Hui <[email protected]>
Sender: [email protected]
Date: Tue, 24 May 2011 22:47:47 
To: Programming forum<[email protected]>
Reply-To: Programming forum <[email protected]>
Subject: Re: [Jprogramming] J arrays

_1+2^n-1 where n is the number of bits in a machine word.
(n is 32 or 64).



----- Original Message -----
From: Charles Holder <[email protected]>
Date: Tuesday, May 24, 2011 22:24
Subject: [Jprogramming] J arrays
To: [email protected]

> What is the max items an array can have?

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to