gamut v0.0.7 ask for what you want
Guillaume Piolat
first.last at spam.org
Thu Aug 11 11:26:50 UTC 2022
On Thursday, 11 August 2022 at 11:06:43 UTC, wjoe wrote:
>
> I imagined you could allocate internal buffers for
> encoding/decoding on the stack but your reply suggests
> otherwise.
Yes.
For example, the QOI-10b codec needs an pallete of 256 16-bit
RGBA, that's 2 kb. Is that portable? There is probably a size at
which it isn't that portable anymore.
It also needs two scanlines of 16-bit RGBA, that is O(n) with the
image width, so can't go to the stack.
Now this encoder state is allocated at the end of the encoded
pixels, since it would be too large for a portable stack.
(Regular QOI can be all on the stack though.)
I mean, the primary thing you want is performance, complete
control over the memory is just a proxy for that.
> However shouldn't a single function call back be enough?
> Something like
>
> ``` D
> void[] need_more_ram(size_t amount, void[] old_chunk, void*
> user)
> {
> MyAllocator* a = cast(MyAllocator*)user;
> void[] result = a.alloc(amount); // MyAllocator would return
> an empty slice if amount == 0
> if (amount && chunk.length) result[0..chunk.length] = chunk;
> // it is assumed that on re-allocation amount > chunk.length
> a.free(chunk.ptr);
> return result;
> }
> ```
Indeed, that would quite fitting as an API.
More information about the Digitalmars-d-announce
mailing list