Any member data stored in your C++ objects will retain the properties of their respective C++ data types. If you have an object that encapsulates a C++ vector, none of that changes. However, whatever you pass back to Perl becomes a Perl SV, AV, or HV (for example). So let's say you've got a vector of a million ints that consumes 4mb on a 32bit int system. Pass that whole structure back to Perl and you'll be sitting on a substantially larger chunk of memory. Maybe 48meg (just a very rough guess; I didn't put a pencil to it). But if you pass just one int out of the vector, it becomes a simple SV, and consumes roughly 16 bytes if I recall. So pass data out of C++ just like you would read a file; one chunk at a time rather than a big slurp.

Think of it this way: Anything retained inside of the C++ code will be using the data types and memory footprint of C++. Anything you pass to Perl will be using a Perl data type. However, this same limitation would be in play even if you hand-crafted the XS code yourself.

I know that one of the uses for Inline::C and Inline::CPP is to let those modules create the XS code that you would then lift out and use for your own modules with minimal changes.


Dave


In reply to Re^5: returning an object in XS by davido
in thread returning an object in XS by bipham

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.