are perl-arrays real arrays 
Author Message
 are perl-arrays real arrays

hi,

i can't find an answer to this in the FAQ nor in any perl-book I own:

what is the internal representation of perl-arrays? are they implemented by
succesive chunks of bytes in main menmory, each chunk for one array element?

or are they some sort of hashes, internally?

how is the dynamical growing achieved? by doubling the corrsponding C-array?

maybe you can help me,

greetings from germany

joachim



Sat, 07 Feb 2004 17:35:28 GMT  
 are perl-arrays real arrays

JZ> hi,
JZ> i can't find an answer to this in the FAQ nor in any perl-book I
JZ> own:

JZ> what is the internal representation of perl-arrays? are they
JZ> implemented by succesive chunks of bytes in main menmory, each
JZ> chunk for one array element?

JZ> or are they some sort of hashes, internally?

JZ> how is the dynamical growing achieved? by doubling the
JZ> corrsponding C-array?

JZ> maybe you can help me,

Not sure but maybe 'perldoc perlguts' can help you.

--
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Sat, 07 Feb 2004 17:41:16 GMT  
 are perl-arrays real arrays

Quote:

> JZ> hi,
> JZ> i can't find an answer to this in the FAQ nor in any perl-book I
> JZ> own:

> JZ> what is the internal representation of perl-arrays? are they
> JZ> implemented by succesive chunks of bytes in main menmory, each
> JZ> chunk for one array element?

> JZ> or are they some sort of hashes, internally?

> JZ> how is the dynamical growing achieved? by doubling the
> JZ> corrsponding C-array?

> JZ> maybe you can help me,

> Not sure but maybe 'perldoc perlguts' can help you.

Or perhaps even a (careful) look into CORE/av.h. ;-)

struct xpvav {
        char*   xav_array;      /* pointer to first array element */
        SSize_t xav_fill;       /* Index of last element present */
        SSize_t xav_max;        /* max index for which array has space */
        IV      xof_off;        /* ptr is incremented by offset */
        NV      xnv_nv;         /* numeric value, if any */
        MAGIC*  xmg_magic;      /* magic for scalar array */
        HV*     xmg_stash;      /* class package */

        SV**    xav_alloc;      /* pointer to malloced string */
        SV*     xav_arylen;
        U8      xav_flags;

Quote:
};

This wont tell you anything about how memory is allocated if one push()s
or unshift()s onto the array, but it gets one a feeling for the
complexity of the Perl-datatypes. hv.h is the equivalent for hashes and
sv.h for scalar variables.

Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->

(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108


ord(chr($h->{$_}))))};



Sat, 07 Feb 2004 17:55:23 GMT  
 are perl-arrays real arrays


Quote:
> what is the internal representation of perl-arrays? are they implemented by
> succesive chunks of bytes in main menmory, each chunk for one array element?

I suggest reading the excellent "Shift, Pop, Unshift and Push with
Impunity!" as an introduction to this subject:
http://www.perlmonks.org/index.pl?node_id=17890

Blop!



Sat, 07 Feb 2004 18:02:38 GMT  
 are perl-arrays real arrays


Quote:
> what is the internal representation of perl-arrays?

Have a look at "Perlguts Illustrated": http://gisle.aas.no/perl/illguts/
(the bit starting at "AV").

Quote:
> are they implemented by succesive chunks of bytes in main menmory,
> each chunk for one array element?

No. There is a C array, but it's an array of pointers to SV's, which
represent the individual elements.

Lots of pointers in the internal guts. You think you have an array of
strings, but what you have is probably an AV*. In the AV structure, you
have a pointer to a struct xpvav, which has a pointer to a C array. This
array has pointers to SVs, which have pointers to struct xpv, which have
pointers to a C array containing the characters in the string.

Quote:
> how is the dynamical growing achieved? by doubling the corrsponding
> C-array?

Not sure about that. Read the code -- probably in av.c. But first make
sure you really want to know (and that you can read C macros) :)

Cheers,
Philip
--

That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.



Sun, 08 Feb 2004 18:54:37 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. assign an array in a hash to a real array

2. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

3. Arrays (real easy question probably)

4. array of arrays of arrays

5. Separating array into alphabetical array of arrays

6. What am I doing wrong? Arrays

7. Array initialization, what am I doing wrong?

8. Am I looking at an anonymous array

9. Perl 5.001e subroutine returns length of array instead of array

10. Efficiency/New Perl Book: return @array vs \@array

11. Efficiency/New Perl Book: return @array vs \@array?

12. Arrays of associative arrays in perl 4.0

 

 
Powered by phpBB® Forum Software