da_resize? A easy way to do this in G'MIC?

I’m looking to resize dynamic array using size each time. As to why, I want to change my rep_bin2dec to perform multi-threading to output massive binaries (256000+ binary digits) as decimal with at least reasonable speed, and something like da_resize makes that realistic of a goal.

I don’t get the use case for a da_resize().
Never use dynamic arrays with multiple threads except if:

  • You put your da_push() and da_pop() in a critical() section.
  • Or, you have as many dynamic arrays as there are threads, so each thread manages its very own da.

Let`s say you want da_array to start with a specific size. Okay, da_resize allows you to do this while still retaining the property of dynamic array. Now, to come to think of it, da_clear() would be nice.

And yes, I know of that tip.

OK, so maybe I can explain how a dynamic array is stored. It’s actually quite easy:

A dynamic array of size N with S channels is stored as a 1-column image, with S channels and with a height that is at least equal to N+1.
The size of the dynamic array is always stored at position i[h#ind-1] = i(0,h#ind-1,0,0).

So, if you want to create a dynamic array with a specific size (e.g. 100 RGB colors), you can do something as simple as that:

foo : 
  1,101,1,3,v([255,255,255]) =. 100,0,{h-1}
  eval "da_push([100,100,100])" # Works OK, add a 101 elt in the dynamic array.

Note that the height or your image is decided by the dynamic array functions.
In my example, inserting a single RGB color in the dynamic array changes its original height from 101 to 202. It still is considered to contain 101 elements, but it keeps room for possible further insertions (changing the image size for each element inserted would be too costly in practice).

Actually, this whole thread was for nothing. I figured out how to improve my recent binary to decimal conversion algorithm without needing something like that.

When the size can be known, I tried to find out the maximum size, and used that, and it worked.