Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: XS Storing AV in HV entry

by SarahM (Monk)
on Apr 04, 2003 at 17:40 UTC ( [id://248146]=note: print w/replies, xml ) Need Help??


in reply to XS Storing AV in HV entry

You just need to put a reference to the AV in the HV. (notice the newRV_inc()) The following code is untested (I don't have a compiler on this computer) but should give you the right idea.
AV * array = newAV(); HV * hash = newHV(); // use AV_store() to put something in the array HV_store(hash, "key3", 4, newRV_inc((SV *) array), 0);

Replies are listed 'Best First'.
Re: Re: XS Storing AV in HV entry
by Elian (Parson) on Apr 04, 2003 at 20:37 UTC
    This is almost right--you want newRV_noinc, not newRV_inc. The AV you've created already has a refcount of 1, so there's no need to increment it again.

    Note that, if only your XS code accesses the array, you can stick the AV directly in. (It works, AVs are supersets of SVs, at least for this purpose) Do not access an array stored like this from perl code, though, as bad things will happen. (core dumps and fatal errors. Not good)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 21:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found