in reply to Re^3: returning an object in XS
in thread returning an object in XS

Hi David, The reason I was doing all this in C++ is because I wanted to reduce the memory footprint of my objects. So I would like to ask if the object produced by Inline::C or Inline::C++ will have the C/C++ memory size or it will be the same as in perl? I am trying to design a database that can contain large dataset. Will Inline::C++ give me what I need? Thanks David,

Replies are listed 'Best First'.
Re^5: returning an object in XS
by davido (Cardinal) on Feb 29, 2012 at 23:23 UTC

    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