Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » String::Make - new way how to create a small string fast
String::Make - new way how to create a small string fast [message #57545] Sat, 18 September 2021 17:31 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
While optimizing conversion routines, I have found a relative bottleneck when converting small char buffers to String. To solve that, there is now a new static method


template <class Maker> static String Make(int alloc, Maker m)


Optimized static method for creating Strings. This method creates internal buffer of at least alloc and then invokes lambda m passing the char * pointer to the internal buffer as lambda parameter. Lambda is then supposed to fill the characters to this buffer and return the length of string (which must be <= alloc). For the best performance, alloc should be constant.

Example:

String x = String::Make(12, [](char *t) { *t++ = 'X'; return 1; });

[Updated on: Sat, 26 February 2022 18:51]

Report message to a moderator

Re: String::Make - new way how to create a small string fast [message #58098 is a reply to message #57545] Mon, 14 February 2022 15:23 Go to previous messageGo to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
Did you mean
String x = String::Make(12, [](char* t) { *t++ = 'X'; return 1;} );

in your example?

[Updated on: Mon, 14 February 2022 15:28]

Report message to a moderator

Re: String::Make - new way how to create a small string fast [message #58099 is a reply to message #58098] Mon, 14 February 2022 15:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Yes, thank you, corrected.

Mirek
Re: String::Make - new way how to create a small string fast [message #58100 is a reply to message #58099] Mon, 14 February 2022 15:50 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
You still missed the single quotes on the char. Very Happy
Previous Topic: Merry Christmas and Happy New Year 2022!
Next Topic: IME improved support
Goto Forum:
  


Current Time: Fri Mar 29 16:28:33 CET 2024

Total time taken to generate the page: 0.01852 seconds