> Hello all,
> I am trying to obtain the size of a java object in C by using JNI. As
[quoted text clipped - 5 lines]
> find/estimate the length of the string with as much ease as it is in C
> via JNI.
What is wrong with the length() method of String?
> Sizeof impl in C seem to be centred around primitives and structs
> etc...
The results of the sizeof operator are calculated by the C compiler. That is
inherent to the C language. Know your languages.
> So, how do I find the sizeof a java object being sent via native method
> call to a C program? Do I need to allocate memory for this object
> [estimation based]?
If the object exists in Java, memory is already allocated for it.
> I tried loading the jobject into a struct but sizeof always gives me 4
> whether it is via sizeof(jobject) or sizeof(struct myjostruct)!!!
> I understand that this is the size allocated for the address in memory.
Have you looked at the declaration of the jobject struct/typedef?
To solve your problem, you could dive deeply into the source code of your JVM,
trying to find out how it keeps track of object size. The easy way would of
course be reflection.