Author Topic: Copy operator for records question  (Read 767 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 19626
  • Glad to be alive.
Re: Copy operator for records question
« Reply #15 on: August 04, 2026, 11:53:56 am »
@jamie: declaring a Copy operator for a record disables the default copy mechanism and you need to manually handle each and every field of the record.
Which I already explained in my first answer, but probably not clear enough. Thanks for the exact wording.
Many people just still don't understand implementing the copy operator.
« Last Edit: August 04, 2026, 12:01:36 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Copy operator for records question
« Reply #16 on: August 04, 2026, 01:06:11 pm »
As for dynamic arrays verses Strings, is there reference counting also for the managed dynamic arrays too?

Yes.

Also note that to copy a dynamic array's data, you'll have to use  SetLength  (which works even if the new length is the same as the old length - it's not a no-op). There's no direct analog to  UniqueString  (that I know of, at least - though something like  generic procedure UniqueArray<A>(var Items: A); begin SetLength(Items, Length(Items)) end;  should do the trick.

Ok, i think i may switch over to using short strings and manual memory handling due to performance for some of my advanced records.

Thanks.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 19626
  • Glad to be alive.
Re: Copy operator for records question
« Reply #17 on: August 04, 2026, 01:48:45 pm »
Ok, i think i may switch over to using short strings and manual memory handling due to performance for some of my advanced records.

Thanks.
- First you did not listen (Took PascalDragon to put all of you wrong and my first answer right)
- And then you listen to people who equally do not understand it?

That is gross.

Gimme some code where something is slow and I honestly try to fix it.
Anyway, using shortstrings may very well be your answer (in records these are flat, not pointers), but I doubt it.
You are put on the wrong foot.
Using the Copy management operator may actually speed up your code, even if it takes a few more lines of code. But that greatly depends on purpose.

Where are those "some of my..."?  Show them. And show how you use them (because that is likely where they go slow)
« Last Edit: August 04, 2026, 02:07:14 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Copy operator for records question
« Reply #18 on: August 05, 2026, 12:48:40 am »
@Thaddy, I am still using the Copy operator, I didn't say I was not going to. I still need to make changes at some point on the transferred data.

Thank you very much and have a good day!

Jamie
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018