in reply to Re: how array variables are stored in memory
in thread how array variables are stored in memory

The container uses contiguous memory, but its elements are pointers to SV structures. The structures can reside anywhere (as your demonstration illustrates... or your illustration demonstrates), but that doesn't change that the array itself is a contiguous container.


Dave

  • Comment on Re^2: how array variables are stored in memory

Replies are listed 'Best First'.
Re^3: how array variables are stored in memory
by Athanasius (Archbishop) on Feb 06, 2014 at 06:58 UTC

    Ah! so the “elements” of an array are always pointers. (So, accessing an element: $array[2] requires at least two dereferences: one for the subscript and another for the pointer.) Thanks, I didn’t know that! I really must read up on Perl internals. Best place to start?

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      perlguts and perlxstut

      You kind of have to read both at the same time; they each assume deep knowledge of the other (which is pretty much how your entire XS learning experience will be).

      Inline with Inline::C is probably the easiest way to get started, as it allows you to do the simple things without getting bogged down in internals. Then as you start to venture into solving more difficult problems, you can start adding knowledge gleaned from perlguts. Another trick is to think of some function that you know exists in XS form on CPAN. Read its source code. It will look like chicken scratch. Then investigate why each line is there (by reading perlguts, perlapi, perlcall, perlxstut, and so on). When you're done, you'll understand why it's written how it is written. You may discover a bug or two along the way. ;) And you'll be able to apply those patterns you learned to some of your own work.


      Dave