[omniORB] sequences and java

Gary D. Duzan gdd0@gte.com
Fri, 23 Apr 1999 10:11:27 -0400


In Message <372080DA.86822AB7@itwm.uni-kl.de> ,
   lojewski <lojewski@itwm.uni-kl.de> wrote:

=>hallo!
=>i want to transfer a byte stream from a server to a client. here is an
=>example:
=>
=>typedef sequence<char> ImageData;
=>interface Jvcl {
=>  ImageData getImage();
=>};

   One point: assuming that your image contains binary data, you should
use sequence<octet> instead of sequence<char>. A CORBA::Char can be
modified my the ORB to match a local character set, while a CORBA::Octet
is always sent unmodified.

=>because the size of the image can change i use a sequence. on the java
=>client side i do:
=>char[] data = ref.getImage(); its ok !
=>on the server side, there is a global pointer to an image : char *image,
=>and a long variable l for the size of the image. the image is allocated
=>on the heap.
=>
=>on the server-side i do this:
=>
=>jvcl_i::getImage(){
=>
=>ImageData *id=new ImageData();
=>id->length(l);
=>now i copy l bytes from the global image to id (is there a better way ?)

   Not portably in a 2.0 ORB, unfortunately. I think this is addressed
in the CORBA 2.2 C++ mapping.

=>for(int i=0;i<l;i++)
=>(*id)[i]=image[i];
=>return id; now i transfer the data
=>}
=>
=>i dont delete id , is this a memory leak ? or would id be destroyed ?

   Return values/out parameters of CORBA operations are consumed by
the ORB, so there is no leak.

=>can i use the global image pointer to transfer the data directly and how
=>to do this ?
=>how can i transfer data from the stack in getImage method ?(e.g. char
=>c[500] is on the stack)

   Again, not portably. However, from a quick look at the code
(omniORB_2.7.1/include/omniORB2/seqtemplates.h:315) you might try:

	ImageData *id=new ImageData(l, l, image);
	return id;

This may or may not work -- I haven't tried it -- and if it does it will
be OmniORB-specific.

					Gary Duzan
					GTE Laboratories