[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How unpack a charNDArray using pvm library?
From: |
John W. Eaton |
Subject: |
How unpack a charNDArray using pvm library? |
Date: |
Fri, 2 Mar 2007 15:07:23 -0500 |
On 28-Feb-2007, Riccardo Corradini wrote:
| DEFUN_DLD(pvm_pkcharMAT,args,, "This function emulates the C function
pvm_pkbyte of pvm3 library, but packs any char matrixes with any dimensions \n")
| {
|
|
|
| octave_value_list retval;
| double nargin = args.length ();
|
| if (nargin != 2)
| {
| error ("expecting 2 input arguments");
| return retval;
| }
|
| const charNDArray tarray = args(0).char_array_value();
| int nitem = tarray.capacity();
| char *p = const_cast<char*>( tarray.data() );
I dont' think you should be using const_cast here. Octave is not
designed for you to be modifying arguments passed to functions. If
you need to do that, you need to make a copy, and return the copy to
the caller. To do that, write
charNDArray tarray = args(0).char_array_value ();
char *p = tarray.fortran_vec ();
Or, if it is just that
| int info2 = pvm_pkbyte (p, nitem, stride);
has the wrong declaration for the first arg (char* instead of const
char*), and it really doesn't ever modify the contents of the vector,
then maybe you should fix the declaration of pvm_pkbyte?
| // Could I use an octave_local_buffer macro if so .. how?
| charNDArray oar (dv);
| if( (n != oar.capacity()) )
| {
| error ("errors with dims");
| return retval;
| }
|
| char *preal = const_cast<char*>( oar.data() );
Again, I dont' think you want a const_cast here. Use
char *preal = oar.fortran_vec ();
| int info1 = pvm_upkbyte (preal, n, stride);
| retval(0) = static_cast<int>(info1);
It looks like the type of info1 is already an int, so why do you use a
cast here?
| return octave_value_list(retval);
The variable retval is already an octave_value_list, so you can just
write
return retval;
jwe
- How unpack a charNDArray using pvm library?,
John W. Eaton <=