Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - ReadMemBlockString & WriteMemBlockString Functions

Author
Message
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Jun 2014 19:57 Edited at: 25th Jun 2014 19:59
ReadMemBlockString & WriteMemBlockString Functions

While looking through the memblock commands, they seemed to be missing some read and write string functions. Which would be simple if you could get a pointer to the string, but couldn't work out a way to do it without restoring to Matrix's plug ins. In fact, if you want quicker string support in DBpro install them !

The functions are included with a bench mark also. The aim was to try a few different ways against the naive solutions, since those turned out to be really slow. To make them quicker just comes down to how many len() and potential allocations you can remove from the string thrashing, while using just the native string functions.

The results turned out better, but still a bit slower than i'd like..




Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 11th Jul 2014 13:57
Here's a faster WriteString implementation that uses the fact that the DBPro compiler passes strings as pointers to dll calls:


You can theoretically read a string from a memblock in much the same way if you can set up a pre-allocated string of the required size, which would be a lot faster than having to step through each character of the memblock string and appending them to the output string.


"Why do programmers get Halloween and Christmas mixed up?"
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 11th Jul 2014 14:17
After some snooping around this will work for fast string reading and writing to memblocks without the need for additional third-party plugins:




"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2024-03-29 15:58:38
Your offset time is: 2024-03-29 15:58:38