[Qt-jambi-interest] QNativePointer to void*
Karim Andras Pinter
pinterkarimandras at yahoo.co.uk
Thu Aug 14 11:00:33 CEST 2008
Thanks for your fast relpy!
I meant that there is a Java function which returns QNativePointer and what is returned should be accessed directly on the c++ side without copying as a void*.
Is there any opportunity to reach Java data directly as a pointer without copying the data using Jambi? (or is it necessary to use JNI?)
If yes how would the typeset look like?
Lets say:
Java: void Converter( QNativePointer qnp )
c++: void Converter( void* qnp )
How the typeset would look like?
I hope I managed to explain my problem more correctly :-)
Thanks for your help!
Karim
--- On Thu, 14/8/08, Gunnar Sletta <gunnar at trolltech.com> wrote:
> From: Gunnar Sletta <gunnar at trolltech.com>
> Subject: Re: [Qt-jambi-interest] QNativePointer to void*
> To: pinterkarimandras at yahoo.co.uk
> Cc: qt-jambi-interest at trolltech.com
> Date: Thursday, 14 August, 2008, 10:41 AM
> Karim Andras Pinter wrote:
> > Hello!
> >
> > I would like to create a utility class using jambi
> generation.
> > One of the class functions should be like this:
> >
> > Java side :
> > void converter( byte[], QNativePointer )
> >
> > C++ side :
> > void converter( char*, int, void* )
> >
> > So basicly byte[] -> to void* and lenght of byte[]
> and QNativePointer -> void*.
> > Questions are : Is it possible to use QNativePointer
> as a void* if the length is known?
> > How will the typesetting will look like? How the
> QNativePointer can be converted to void*?
> >
>
> The best place to start, before doing any removal etc, is
> to see how the
> C++ function maps to Java. For the above case you should
> get (I'm just
> making up variable names):
>
> C++: void converter(char *str, int strLength, void *data)
>
> Java: void converter(QNativePointer str, int strLength,
> QNativePointer data)
>
> In the above, "str" will be typed to char and be
> 8-bit on the native
> side while data will be typeless and size of pointers,
> 32-bit or 64-bit
> depending on target system.
>
> In your case I would make the java converter function
> private and
> introduce another converter function which has the API you
> prefer which
> translates between the two.
>
> so in typesystem:
> <modify-function signature="..."
> access="private"
> rename="convert_private"/>
>
> And inject code next to the private convert function that
> looks
> something like this (this code is unchecked, not compiled
> and comes with
> no guarantee ;-)
>
> void converter(byte str[], QNativePointer data) {
> QNativePointer charPtr = new
> QNativePointer(QNativePointer.Type.Byte, str.length);
> for (int i=0; i<str.length; ++i)
> charPtr.setByteAt(i, byte[i]);
> convert_private(charPtr, str.length, data);
> }
>
> That should give you the API you need, but as you can see,
> there will be
> copying from str to charPtr via a number of JNI calls which
> is not the
> fastest thing.
>
> An alternative is to simply write the functions by hand, by
> declaring
> your converter() function native and use the JNI functions
> to access the
> char* of the byte[] directly, but the JVM may still decide
> on giving you
> a copy of the data rather than a pointer to internal memory
> so it may
> not be that much faster.
>
> -
> Best regards,
> Gunnar
Send instant messages to your online friends http://uk.messenger.yahoo.com
More information about the Qt-jambi-interest
mailing list