Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^5: returning an object in XS

by davido (Cardinal)
on Feb 29, 2012 at 23:23 UTC ( [id://957054]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://957054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found