Well, "I" means unsigned int with some variability in size.. But no matter..if these scores are that big (>=4 bytes), then why even bother with pack()? Pass around something (update: "something" here means pointer to a hunk of memory) that is X x Y ints big which is what I suggest even if the scores are as small as 8 bits.

I am also challenging the need for 'C' in the first place. There may some false assumption about Perl math performance. Yes, Perl is far slower than 'C', but its not 20x slower and actually does surprisingly well on "int" operations.

Update:

I see how I got onto this "char" idea, it was from the byte_stream name and I remembered the "byte" part. Continuing on with this "compact" requirement...let's say we have 1 million 1 byte integers. That takes 4MB on my 32 bit machine. What will happen if we "pack" that? It will take even MORE memory! pack() will not overwrite the original 4MB and will use 1MB more for the "packed" version. The percentage growth in memory usage is even worse if these are 16 bit integers. As far as speed goes, there are some complex "yeah but's" that depend upon how good your memory sub-system is. However it is hard for me to imagine how "packing" could work out well.

In short: if you have a memory structure that you want to send to some sub(), "packing" is literally a waste of time and memory. Send a pointer to the memory structure that you already have. In general (I don't know a case where this is not true) your Perl environment will have the same understanding as your 'C' environment regarding how big an "int" is...32 or 64 bits. The 16,24,48 bit systems have gone the way of the dodo bird.


In reply to Re^5: Passing a bytestring from Perl to Inline::C as a 2d array by Marshall
in thread Passing a bytestring from Perl to Inline::C as a 2d array by maasha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.