|
I agree Scott. To return a varying lgth string the called func could ALLOC the bytes needed and then return a pointer to the allocated varying string data. pGetString b dGetString pi * d pString s * d String s 80 a based( pString ) varying c eval pString = %alloc( %size(String)) c eval String = 'some text to return' c return pString p e Only problem is insuring the returned pointer is %DEALLOC'd. now if a DS could have a constructor, destructor and operator member functions .... :) Steve Richter -----Original Message----- From: rpg400-l-admin@midrange.com [mailto:rpg400-l-admin@midrange.com]On Behalf Of Scott Klement Sent: Thursday, October 10, 2002 1:03 AM To: rpg400-l@midrange.com Subject: RE: timings II. const varying vs value varying On Wed, 9 Oct 2002, Steve Richter wrote: > > Its just a hunch of mine. C relies on null term strings so I am speculating > that ILE handles them efficiently. > Yes, I'm familiar with C, since I program in it on Unix machines. Normally, though, when you pass a string in C you pass a pointer. I don't think I've EVER seen a C function that passes a string by value. In fact, it's very difficult to pass a string by value in C. I'm not evern sure that you CAN without using a data structure... Normally you'd do something like this: int myfunc(const char *input, char *output, int size); Which means that the input is a pointer to a null-terminated string, passed as "const" (so you can't change it in the function) the output is also a pointer to a null-terminated string. This would be equivalent to the following RPG prototype: D myfunc PR 10I 0 D input * value options(*string) D output * value options(*string) D size 10I 0 value See? You're passing the strings by pointer, i.e. by reference. So you really can't compare it to a varying field passed by value. To pass by value in C you'd have to do something like: #include <stdio.h> struct stuff { char mystring[32000]; }; int myfunc(struct stuff t) { printf("%s\n", t.mystring); return 0; } int main(void) { struct stuff b; strcpy(b.mystring, "This got passed by value!"); return 0; } So, that's about the same thing as: D myfunc PR 10I 0 D string 32000A value Even though the string is "variable length" (i.e. null-terminated) in C, it still copies all 32000 bytes. So I would expect it to actually be less efficient than the RPG counterpart. I suppose I could write up a benchmark and try it... but this message is already getting long :) At any rate, nobody EVER passes strings by value in C. So, I SERIOUSLY doubt you'd find it more efficient than RPG. _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@midrange.com To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l or email: RPG400-L-request@midrange.com Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.