Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
my $tree = new_tree(); print node_count($tree), "\n"; __END__ __C__ typedef struct { int count; } Tree; SV* new_tree () { Tree* tree; tree.count = 0; /* return tree some how */ } int node_count (SV* tree) { /* get back at tree some how */ return tree.count; }
I have seen the Inline::C-Cookbook example of OO. I don't want an object. If this were pure C, I would pass in a pointer to new_tree and not return anything (glossing over malloc and free). In the CB, tye mentioned "allocate PV space in an SV and stuff it there" which conceptually I understand but have no idea on the implementation. Feel free to mention perlapi, perlxstut, perlguts illustrated, etc though I have all of them on my reading list. I would like a working example to play with as I read though. I know this means I am going to have to handle memory management myself and I am fine with that.
Thanks in advance.
Cheers - L~R
|
|---|