Page 1 of 1

Creating a large Data of a specified length

Posted: Sat Jul 20, 2019 3:26 pm
by DarScott
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?

Re: Creating a large Data of a specified length

Posted: Sat Jul 20, 2019 4:28 pm
by [-hh]
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".

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

Re: Creating a large Data of a specified length

Posted: Sat Jul 20, 2019 7:23 pm
by DarScott
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.)