[Kde-bindings] Marshalling char*s

Chris Burel chrisburel at gmail.com
Tue Sep 29 03:01:08 UTC 2009


Hey guys,
I'm trying to figure out the correct way to handle char*s in PerlQt4.
It seems like it should be pretty simple, but I've run into some
problems with implementing the network/broadcastreceiver example in
Perl.  Ruby has this implemented just fine, so I'm wondering what I'm
doing differently.

The receiver.rb file has the following code:
 58 datagram = Qt::ByteArray.new
 59 datagram.resize(@udpSocket.pendingDatagramSize)
 60 @udpSocket.readDatagram(datagram.data(), datagram.size())
The call to readDatagram populates the data segment of the datagram
QByteArray, which is what's confusing me.  When this code executes,
it's going to call datagram.data() first, and allocate a ruby variable
to hold the resulting char*, making a copy of the memory.  It then
feeds that ruby variable to readDatagram(), which marshalls Ruby var
back to a char*, copying it again.  So now we're 3 copies away from
the source QByteArray data.  Then readDatagram modifies the char*.
Ok, after the readDatagram call is done, I can modify the original
Ruby variable that it was copied from to match the new value.  But the
call to datagram.data() has already executed and completed.  How does
the new value get populated all the way back up to the source
QByteArray?



More information about the Kde-bindings mailing list