Subject: Re: How are nested arrays internally stored?
From: mclean@futon.SFSU.EDU (Emmett Mclean)
Date: 10 Feb 94 22:42:35 PST
Organization: San Francisco State University

 lefevre@ACFcluster.NYU.EDU writes:

>>How are nested arrays internally stored ?

>Berni@nw42.wiwi.uni-bielefeld.de writes:
>
>What a pithy question ! As I see it, the problem is that APL stores small
>integers as 4-bits chunks but needs 8 bits for floating point numbers.

 This is more or less the case with J. Internally J can handle boolean,
 character, double, long integer, and J data types. The different types
 for integer, and double, etc speeds up computations, reduces the
 memory usage, and makes memory allocation more efficient.

>Thus a question arises with regard to mixed nested arrays : how big are they ?

 Speaking for J :

 The easy way to determine this is to make an assignment while
 using the space verb.

 Nested - or boxed - data types in J have pointers to other J structs.
 So, they are as big as the sum of all the data types for the component
 parts, plus the memory for the struct which keeps the entire nested
 array together.

 However, J uses a reference count scheme and there may be instances
 where the duplication of memory is reduced (due to this scheme) but
 I am not familiar with the details.

>The answer is : it depends. In some cases, nesting the floating point numbers
>prevents the array from going all 8-bit but not always.

 In J the size of doubles depends on the size of doubles for that
 machine and that C compiler.

 If you are curious about the bit size of various data types, and
 of various machine specific constants for your machine I recommend
 that you compile the C program enquire at comp.sources.misc. In fact
 the most recent version of enquire builds limits.h and float.h -
 header files which you can use in your applications.  Use of enquire
 makes it so that you do not have to keep track of machine specific
 constants from machine to machine and compiler to compiler.

>I'm afraid the
>answer will vary from one product to another but I, too, would like to know
>the precise rules, so as to be able to make more informed programming
>decisions.
>
  Yes....

  Arthur Whitney uses a list of lists scheme for his data structures
  which, he says, provides for fast appending.

  For example in the statement

  a=. 3 4 5
  a=.a,: 6 0 0

  Memory for a J data type for 6 integers is allocated and the
  3, 4, 5, and 6 0 0 are copied into a new place in memory. Then the
  memory for the old 3 4 5 is freed.

  I think Arthur said that in K memory for the 6 0 0 is allocated
  and then a pointer in the old 3 4 5 is assigned to point to the
  6 0 0.  Furthermore, K employes an efficient memory allocation
  scheme where several blocks of memory are allocated at once.
  Even when he uses memory mapping and virtual memory he has
  a scheme, I think based on minimizing memory paging, which
  allows statements such as a ,: 6 0 0 to not require memory
  allocation.

  When comes to K I'm kind of speaking from what I've gleaned in
  conversations. And memory mangagement isn't something I know
  much about, so I might have misstated some of the details.

  Finally, once Arthur asked : What do YOU think the most efficent
  struct ought to be?

  His point was that one is only limited by his imagination,
  programming capabilities, and motivation.

  Emmett

>Thanks beforehand.
>
>Olivier Lefevre (NYU Medical School, NY)

