Recent

Author Topic: TFPGMap vs TFPGMapInterfacedObjectData  (Read 468 times)

JdeHaan

  • Full Member
  • ***
  • Posts: 150
TFPGMap vs TFPGMapInterfacedObjectData
« on: November 12, 2024, 12:17:32 pm »
I want to create a map of an iUnknown descendant and a variant value.

Which map type should I use?

TFPGMap<iUnknown, Variant>

or

TFPGMapInterfacedObjectData<iUnknown, Variant>


Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: TFPGMap vs TFPGMapInterfacedObjectData
« Reply #1 on: November 12, 2024, 12:38:19 pm »
It depends on how you use it. Both should be fine. Athough variants are not really my thing: I avoid them when possible.
If I smell bad code it usually is bad code and that includes my own code.

JdeHaan

  • Full Member
  • ***
  • Posts: 150
Re: TFPGMap vs TFPGMapInterfacedObjectData
« Reply #2 on: November 12, 2024, 05:14:52 pm »
Thanks Thaddy.
The Value part in the map can be anything, integer, float, Boolean, char or String. What other solution could there be?

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: TFPGMap vs TFPGMapInterfacedObjectData
« Reply #3 on: November 12, 2024, 05:18:12 pm »
Well, that is the point: if you use those different data types over the same class instance, you would use a variant, but if you can determine it is the same for the same class instance you would never use a variant, because variants are dead slow, really slow.
Which means that, although the map can be reasonably fast, you are stuck with slow code.
Note that slow code is not equal to bad code, but you should carefully consider your design.
Variants are slow, period. They are not a magic wand.
« Last Edit: November 12, 2024, 05:24:31 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: TFPGMap vs TFPGMapInterfacedObjectData
« Reply #4 on: November 14, 2024, 09:25:02 pm »
I want to create a map of an iUnknown descendant and a variant value.

Which map type should I use?

TFPGMap<iUnknown, Variant>

or

TFPGMapInterfacedObjectData<iUnknown, Variant>

The TFPGMapInterfacedObjectData<,> is intended for interfaces as the data and not the key. So if you want to use Variant as the data then you should use TFPGMap<,>.

 

TinyPortal © 2005-2018