1. Tom Peters
  2. PowerBuilder
  3. Wednesday, 5 September 2018 20:48 PM UTC

Hello, All!

First, this is not critical. I am in the exploratory stage, only, and open to looking at other solutions to my problem.

My PowerBuilder application needs to do (potentially) thousands of concatenations to a single string variable. True to form, PB slows down as the immutable string is appended over and over. Totally understandable with an immutable type.

Per the book "PowerBuilder 9: Advanced Client/Server Development", I'd like to write my own string handler (like a C# StringBuilder equivalent) in C++ and then "create a PBNI PowerBuilder object to use in place of the native string function".

Reading through the PowerBuilder Native Interface Programmers Guide and Reference it looks like I need to use the PBString type in C++ which does not seem to be mutable in the C++ world, either.

  1. Is the PBNI PBString type mutable or immutable?
  2. Is the PBNI PBString limited to 32K like its PB counterpart or is it more like std::string which will utilize as much available RAM as needed?
  3. Can my exposed function use a std::string parameter type or will PB choke on that, expecting PBString?

Disclaimer: As you may have discerned, C++ is not my thing and this is my first stab at PBNI.

I have tried to write the C++ DLL code, but I cannot figure out how to append the incoming strings because C++ appears to only pass pointers. I have not been able to find out how to get the real string value. If I have to convert from pointer to PBString to std::string, then this is a pointless exercise, anyway.

Does PB already have a mutable string type that I have either missed for 25 years? Is Appeon thinking about it? I've tried using Blobs instead of Strings, but the performance is the same.

Thanks,

Tom

 

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 6 September 2018 03:19 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Tom;

  For super fast string concatenation in PB Apps, try the BlobEdit ( ) command.

 For example:

blob{100000}   lblb_blob
string   ls_output
long     ll_loop, ll_pos = 2, ll_cpu

ll_cpu = CPU ( )
FOR ll_loop = 1 to 10000
    ll_pos = BlobEdit (lblb_blob, ll_pos - 1, "PB2017R3 Test Data ",  EncodingANSI!)
NEXT

ls_output = String (lblb_blob, EncodingANSI!)

MessageBox ( "BlobEdit time: " + String ( CPU() - ll_cpu, "#,##0" ) + "ms" )

 

HTH

Regards ... Chris

Comment
  1. Tom Peters
  2. Thursday, 6 September 2018 12:34 PM UTC
Hi Chris -

Shame on me! John did mention in his book to "use the BLOB capabilities in PB". I thought that reference meant to do something like lblob += Blob("test") which, of course, was only slightly faster. I tested the BlobEdit and it went from 89,700ms to 78ms. Now, that's fast!

Thank you!

Tom
  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 6 September 2018 14:30 PM UTC




Excellent news Tom ... Yeeehaaaw!



Yes, if you know what C++ code PB is generating in the background - it sure helps to know what PB feature to use in each "Use Case". Being an old "Assembler" guy (no wise cracks here - LOL) - that is why I love studying what "C" code is generated when you build a machine code EXE. You can see how the "C" code gets optimized for each processing scenario. Then, just relate that back to PowerScript and volia, your Apps are "flying" ;-)
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 September 2018 23:32 PM UTC
  2. PowerBuilder
  3. # 1

Hi, 

Before you get into C++ have a look at this (unless you really want C++ of course):

https://blogs.sap.com/2016/10/24/fast-string-concatenation/

I think it's some code by Roland Smith, where he claims string concatenation is 16x faster with the described method.

I haven't used it yet myself, so I cannot say anything else about it.

HIH

MiguelL

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.