in reply to returning an object in XS

There needs to be a typemap that will explain to Perl how to bind a rect * to a Perl structure of some sort. There are several CPAN modules that help to simplify the process. The one I'm most familiar with is Inline::CPP. But I'm highly biased.

The gist of it is that you can create a C++ class that maps to a Perl class. The constructor becomes new(). The destructor becomes DESTROY(), and so on. The docs for Inline::C, Inline::C-Cookbook, and Inline::CPP are required reading in getting started with it. But it's fun (if you're slightly masochistic) once you get the hang of it.

Inline::Struct is compatible with C (ie, doesn't require C++), and will bind C structures to Perl objects too.

There was a time when Inline::CPP wasn't installing on the vast majority of systems out there. Over the last few months we've gotten it to the point that there's only one class of smoke testers that are still having trouble with it (NetBSD -- Any NetBSD pros get in touch with me so we can try to figure it out). Most other common platforms are able to install it and use it. There's also an email list where people can answer questions about the Inline modules: inline@perl.org. See http://lists.perl.org for details.


Dave

Replies are listed 'Best First'.
Re^2: returning an object in XS
by bipham (Novice) on Feb 29, 2012 at 04:23 UTC

    Thanks David, I will give it a try. I'll let you know of the result. Best regards,

      I should mention that if you happen to be one of the unfortunate few for whom it doesn't install, download the latest dev release tarball, unpack it, and perform the mantra. Often the dev releases include tweaks undergoing smoke testing to 'PASS' additional platforms.


      Dave

        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,