Problems? Is your data what you think it is? | |
PerlMonks |
Re^5: returning an object in XSby davido (Cardinal) |
on Feb 29, 2012 at 23:23 UTC ( [id://957054]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|