[fpc-pascal] Dynamic arrays using management operators
Michael Van Canneyt
michael at freepascal.org
Mon Jun 4 16:12:27 CEST 2018
On Mon, 4 Jun 2018, Ryan Joseph wrote:
>
>
>> On Jun 4, 2018, at 5:46 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
>>
>> Well, as far as I can see, you are repeating what the compiler already does for you out of the box.
>
> But it’s customizable, that’s the point. What happens when you remove an element from a dynamic array? I don’t even know where to look in the source code to find out and if I want to change something I can’t. Do dynamic arrays resize memory when you remove elements? Maybe I don’t want that. Maybe I want to grow the array at different intervals, can’t do that either.
>
> I know this is very fringe but I personally needed to customize dynamic arrays to escape that thread safety thing and when I couldn’t I had to make my own array wrapper class which I would have preferred to be a record in many instances, which I can do now. If nothing else it saves me lots of Create/Free calls in countless functions. Pretty good news.
>
> If I actually made a competent implementation (which I’ll do later) dynamic arrays are possibly made redundant even, or close to it (providing the FPC RTL had something like them included).
I do not advocate that you drop your custom record.
I'm just saying that *the management operators* are not needed for your
use-case, based on what I see, if you would use dynamic arrays instead of
manually managing the memory. It will simplify your code.
All the rest of what you do remains exactly the same.
Dynamic arrays do far less than what you seem to assume.
All in all, it seems to me that you do not actually know what dynamic
arrays are really about, so instead of spending a lot of time
re-implementing what is there, maybe better learn what they do
(and don't do).
They make life easier by reducing the need for manual memory
management. No more, no less. Other than that they behave like normal
arrays on the heap.
Michael.
More information about the fpc-pascal
mailing list