I have created a function in LCB that builds a Data filled with zeros based on a specified length. It works fine. (It uses put...after about 2.5log2n times.)
However, I'd like to improve speed. Is there a built-in method or trick or something I have missed?
Creating a large Data of a specified length
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Creating a large Data of a specified length
This needs at most log2(n) times "put after".
What's your handler? And what's your speed?
In LC Script this needs at about 1 second for 1 Gigabyte (2^30 Bytes) of data,
and < 20 ms for 17 Megabytes (2^24 Bytes) of data.
Here is the LC Script handler, the LC Builder handler could use the same "doubling-method".
What's your handler? And what's your speed?
In LC Script this needs at about 1 second for 1 Gigabyte (2^30 Bytes) of data,
and < 20 ms for 17 Megabytes (2^24 Bytes) of data.
Here is the LC Script handler, the LC Builder handler could use the same "doubling-method".
Code: Select all
function createData m,n
put numToByte(m) into b
repeat log2(n)
put b after b
end repeat
return byte 1 to n of b
end createData
shiftLock happens
Re: Creating a large Data of a specified length
Thanks! An adaptation of that will beat my recursive function.
I wonder if there is something like "MCDataCreateOfLength" among the built-ins. (I just made up the name.)
I wonder if there is something like "MCDataCreateOfLength" among the built-ins. (I just made up the name.)