[fpc-devel] Feature request/discussion - SetLengthNoInit
J. Gareth Moreton
gareth at moreton-family.com
Mon Sep 14 19:00:36 CEST 2020
This is something that came up in a discussion with a client. One thing
he noticed when using SetLength with dynamic arrays is that it can cause
a CPU bottleneck because it initialises the entire block to zero, which
is often undesirable if the array is going to be overwritten with its
own values (in his own example, he's passing the array to a GPU shader
as an output buffer). I mentioned that the best ways around this is to
either pre-initialise the array and just reuse it where and when you
need it (object pooling) or to use GetMem and FreeMem, which increases
the danger of memory leaks, dangling pointers and removes the benefits
of a managed type.
With all this in mind, would there be support for an intrinsic such as
"SetLengthNoInit" or "SetLengthNoClear" or some similar name that has
all the benefits of SetLength (especially the reference counting) but
doesn't initialise new elements to zero? If I'm learning one thing, Free
Pascal is finding a niche in some scientific applications, and speed can
be essential sometimes.
Gareth aka. Kit
This email has been checked for viruses by Avast antivirus software.
More information about the fpc-devel