AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Generics - Pro und Contra

Ein Thema von stahli · begonnen am 23. Mai 2014 · letzter Beitrag vom 27. Mai 2014
Antwort Antwort
Dejan Vu
(Gast)

n/a Beiträge
 
#1

AW: Generics - Pro und Contra

  Alt 24. Mai 2014, 08:55
D.h.

Delphi-Quellcode:
Var
  foo : TList<TBar>;
...

Var
  bar : TList<TBar>;
Erzeugt doppelten Code?
Dann muss man also

Delphi-Quellcode:
Type TBarList = TList<TBar>;
Var
  foo : TBarList;
...

Var
  bar : TBarList;
Schreiben und die Welt ist in Ordnung?
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.216 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Generics - Pro und Contra

  Alt 24. Mai 2014, 09:21
Ich habe mich damit nie befasst, aber soweit ich es verstanden habe erzeugt folgendes einmal Code für eine Integer-Liste und einmal Code für eine TObject-Liste:

Delphi-Quellcode:
var
   myIntegerList: TList<Integer>;
   myObjectList: TList<TObject>;
Stevie hat da neulich nochmal zu geschrieben:
Zitat:
This by the way is one of the reasons your empty default applications are growing constantly for the recent releases of Delphi: because now generic collections are used all over the place in the runtime. And when I use TList<TButton>, boom, another 10K added to your binary size (approx in XE5). Too bad if you are using more advanced and feature rich collection types like Spring4D. Then every use adds 65K (actually we got down to that number from close to 100K a few months ago).

How could this be solved? Either by the linker fixing this by figuring out identical methods and removing duplicates (the C++ linker has an option for that called COMDAT folding) or the compiler itself could be smart and generate code for equal types only once. Of course he should pay attention to any use of TypeInfo(T) or T.Create for example because that code is actually different. C# does something like this.
Quelle: Delphi Sorcery
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.583 Beiträge
 
Delphi 12 Athens
 
#3

AW: Generics - Pro und Contra

  Alt 24. Mai 2014, 09:32
In der selben Unit und in Units, welche die erste Unit einbinden, da könnte es das nur einmal geben, aber bei zwei Units, welche sich nicht kennen, da eventuell nicht.



Zu dem Pack:

Also das ist schon ein komisches Zeug, denn der Code wird in den Units garnicht aufgerufen.
Und das Left/Right in der Methode ist nirgendwo definiert. (ist wohl Compiler-Magic?)
Und scheint es nur so, oder kann in einer generischen TList<> eventuell kein NIL-Objekt abgelegt werden, da Pack dafür da ist, um die zu entfernen? [add] Aber das funktioniert nicht, drum knallt es.

Als TList>TObject> funktioniert folgender Code, aber als TObjectList<TObject> macht es bumm.
Delphi-Quellcode:
var
  L: TList<TObject>;
begin
  L := TObjectList<TObject>.Create; //List<TObject>.Create;
  ShowMessage(IntToStr(L.Count));
  L.Add(nil);
  ShowMessage(IntToStr(L.Count));
  L.Add(Self);
  ShowMessage(IntToStr(L.Count));
  L.Add(Self);
  ShowMessage(IntToStr(L.Count));
  L.Add(nil);
  ShowMessage(IntToStr(L.Count));
  L.Remove(Self);
  ShowMessage(IntToStr(L.Count) + ' ' + IntToStr(L.IndexOf(Self)));
  L.Delete(L.IndexOf(Self)); // bei TObjectList knallt es hier
  ShowMessage(IntToStr(L.Count));
  L.Free;
end;
Ein Therapeut entspricht 1024 Gigapeut.

Geändert von himitsu (24. Mai 2014 um 09:40 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:36 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz