Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-02

TLinkedList

29 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello,

If my memory is not misleading me, there was once a TLinkedList class under Classes unit, but I can't find any documentation on it. I found an include file that contains it, but it is not meant for the interface part.

Is there a reason for this ? Should I use records instead ?

Thanks,
Ido

ik
to leledumbo
leledumbo wrote
I don't remember having that since 2.X.X... there was always TList, however. And that's what I was using (I use generics for all my containers use now).

Thanks. Personally I dislike are not that readable imho. Even though FPC's implementation is one of the most readable ways I have ever seen.

Ido

Show quoted text 9 lines
-- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/TLinkedList-tp5469685p5472934.html Sent from the Free Pascal - General mailing list . _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jorge Aldo G. de F. Junior
to ik

I believe generics makes faster code due to having no need to test types during runtime... i maybe wrong.

2012/2/11 ik :

Show quoted text 28 lines
On Fri, Feb 10, 2012 at 17:53, leledumbo wrote: > > I don't remember having that since 2.X.X... there was always TList, > however. > And that's what I was using (I use generics for all my containers use > now). Thanks. Personally I dislike are not that readable imho. Even though FPC's implementation is one of the most readable ways I have ever seen. Ido > > > -- > View this message in context: > http://free-pascal-general.1045716.n5.nabble.com/TLinkedList-tp5469685p5472934.html > Sent from the Free Pascal - General mailing list . > _______________________________________________ > fpc-pascal maillist  -   > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Juha Manninen
to Jorge Aldo G. de F. Junior

2012/2/11, Jorge Aldo G. de F. Junior :

I believe generics makes faster code due to having no need to test types during runtime... i maybe wrong.

It is true only if you use the type-safe "as" casting. Normal casting does not check does make the code more readable. Like:

  MyVar := MyList[i];

compared to

  MyVar := TMyType(MyList[i]);

Also, you get compile time type-checking, just like arrays had from day 1. The code is safer, more readable and self-documenting.

I hope there will be a good and comprehensive generics container library. Now the containers are scattered around and are competing with each other.
Java serves as a good example here. It has a consistent generics container library. Classes are easy to find and use.

Juha

Carver413

doesn't generics more or less duplicate the class every time you use it with different type, and if so would this not cause alot of bloating ?

Juha Manninen
to Sven Barth

2012/2/14, Sven Barth :

Show quoted text 6 lines
Am 14.02.2012 06:45, schrieb Carver413: > doesn't generics more or less duplicate the class every time you use it > with > different type, and if so would this not cause alot of bloating ? Yes it does. So for embedded systems "use with care" ;)

Oh, that is bad!

C++ templates generate lots of duplicate code.

Java's generics do not because it is just "syntactic sugar" allowing the compiler to check types which IMO is enough for most purposes. You don't need ugly type-casts but code-generation is not affected. Perfect.

I know Delphi's and FPC's generics are different but I believed the compiler is clever enough to use the same class when possible. For example, in all cases where objects inherited from TObject are stored in a container, the same container could be used.

This indirectly answered another question I had in mind: Does a generics container for a char or integer use the minimum needed amount of memory?
I guess it does when a new instance of the container class is generated.

Juha

Sven Barth
to Juha Manninen
Juha Manninen wrote 21 lines
2012/2/14, Sven Barth: > Am 14.02.2012 06:45, schrieb Carver413: >> doesn't generics more or less duplicate the class every time you use it >> with >> different type, and if so would this not cause alot of bloating ? > > Yes it does. So for embedded systems "use with care" ;) Oh, that is bad! C++ templates generate lots of duplicate code. Java's generics do not because it is just "syntactic sugar" allowing the compiler to check types which IMO is enough for most purposes. You don't need ugly type-casts but code-generation is not affected. Perfect. I know Delphi's and FPC's generics are different but I believed the compiler is clever enough to use the same class when possible. For example, in all cases where objects inherited from TObject are stored in a container, the same container could be used.

Such logic unnecessarily complicates the compiler. Generics are already troublesome enough.

This indirectly answered another question I had in mind: Does a generics container for a char or integer use the minimum needed amount of memory?

If the container uses thinks like "SizeOf(T)" (where T is the generic type parameter) and such then it does use the least amount of memory. A specialization is basically a reparsing of the generic as if T was the specialization type all along.

I guess it does when a new instance of the container class is generated.

Sorry, but I don't understand what you mean here.

As long as one knows of the disadvantages of generics there is no problem in enjoying their advantages.

Regards,
Sven

Carver413
to Sven Barth
As long as one knows of the disadvantages of generics there is no problem in enjoying their advantages.

the disadvantage will come in the useing. over time more and more units will contain these because they are easy. so you will end up with a lot of redundant code. doesn't matter if they know better or not. they will choose the easy path and let someone else worry about it. just like many of the half ported code that is out there, people port what they need to get there code working then contribute it hoping someone else will finish.

Sven Barth
to Carver413: the disadvantage will come in the useing. over time more and more units will contain…
Carver413 wrote 10 lines
> As long as one knows of the disadvantages of generics there is no > problem in enjoying their advantages. the disadvantage will come in the useing. over time more and more units will contain these because they are easy. so you will end up with a lot of redundant code. doesn't matter if they know better or not. they will choose the easy path and let someone else worry about it. just like many of the half ported code that is out there, people port what they need to get there code working then contribute it hoping someone else will finish.

It won't really matter to you whether some unit you got from somewhere in the internet contains a specialization of a generic TList or whether the list was implemented especially for that type.

Free Pascal is a native language. There aren't much alternatives to code duplication.

Regards,
Sven

Sven Barth
to Marco van de Voort: In our previous episode, Sven Barth said: Afaik it was the main reason to implement…
Marco van de Voort wrote 8 lines
In our previous episode, Sven Barth said: >> in a container, the same container could be used. > > Such logic unnecessarily complicates the compiler. Generics are already > troublesome enough. Afaik it was the main reason to implement generic constraints in Delphi (like .NET)?

Constraints allow the compiler to infer further information on the given types to improve e.g. type checking when parsing the generic, but they won't magically allow the compiler to not duplicate code (in theory it would be possible to do something like Java's generics for cases where the constraints are for descendants of TObject or IInterface, but in my opinion the tradeoffs (increased compiler complexity) are not worth it).

Regards,
Sven

Marco van de Voort
to Sven Barth

In our previous episode, Sven Barth said:

Show quoted text 5 lines
> Afaik it was the main reason to implement generic constraints in Delphi (like > .NET)? Constraints allow the compiler to infer further information on the given types to improve e.g. type checking when parsing the generic,

Exactly. You e.g. know that the unspecialized generic is already meant for reference types, from line one.

Show quoted text 5 lines
but they won't magically allow the compiler to not duplicate code (in theory it would be possible to do something like Java's generics for cases where the constraints are for descendants of TObject or IInterface, but in my opinion the tradeoffs (increased compiler complexity) are not worth it).

Yeah, that is typical. If it is not used inside the compiler it is unoptimized :-)

Maybe redo cclasses with generics?

Jorge Aldo G. de F. Junior
to Marco van de Voort

i once read a textbook about generics (C++ generics) showing how C++ code can end up being FASTER than C equivalent due to lack of type checks...

it uses a quick sort routing as example.

on C you end up having to check the type of storage to get a similar result, while on C++ you check was something along that lines.

the point being made was that object orientation is not necessarely "bloat" but leads to better written code. (not always true, but...)

2012/2/14 Marco van de Voort :

Show quoted text 23 lines
In our previous episode, Sven Barth said: > > Afaik it was the main reason to implement generic constraints in Delphi (like > > .NET)? > > Constraints allow the compiler to infer further information on the given > types to improve e.g. type checking when parsing the generic, Exactly. You e.g. know that the unspecialized generic is already meant for reference types, from line one. > but they won't magically allow the compiler to not duplicate code (in > theory it would be possible to do something like Java's generics for cases > where the constraints are for descendants of TObject or IInterface, but in > my opinion the tradeoffs (increased compiler complexity) are not worth > it). Yeah, that is typical. If it is not used inside the compiler it is unoptimized :-) Maybe redo cclasses with generics? _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Juha Manninen
to Jorge Aldo G. de F. Junior

2012/2/15, Jorge Aldo G. de F. Junior :

i once read a textbook about generics (C++ generics) showing how C++

C++ does not have generics, it has templates. Templates syntax is complex, you can do actual programming with it. IMO, using all its capacity leads to over-engineered and unreadable code. I read about a plan to add Java style generics syntax to C++, in addition to templates. I guess it will not happen. C++ has enough syntax already.

Show quoted text 5 lines
code can end up being FASTER than C equivalent due to lack of type checks... [...] the point being made was that object orientation is not necessarely "bloat" but leads to better written code. (not always true, but...)

Code can still be fast even if it is bloated in size. Object orientation helps in writing readable and maintainable code but that is yet another issue.
The code duplication we discussed here has no advantage for speed. It is quite useless duplication.

From Sven Barth: Free Pascal is a native language. There aren't much alternatives to code duplication.

Yes there is. The same container code can be reused (when possible), just like Java does.
Free Pascal is native, Java generates byte-code, but that is irrelevant here.

I was planning to use generics in many places in Lazarus code but now I must rethink...
Lazarus executable is quite big already.

Juha

ik
to Juha Manninen
Juha Manninen wrote 9 lines
2012/2/15, Jorge Aldo G. de F. Junior : > i once read a textbook about generics (C++ generics) showing how C++ C++ does not have generics, it has templates. Templates syntax is complex, you can do actual programming with it. IMO, using all its capacity leads to over-engineered and unreadable code. I read about a plan to add Java style generics syntax to C++, in addition to templates. I guess it will not happen. C++ has enough syntax already.

You really do not understand the state of mind of C++ :) C++ is like a big pot on a camp fire.
They just throw everything inside, and hope you choose only the food you like to eat, but usually ends up eating fast food instead (Qt, Boost etc...)

Show quoted text 30 lines
> code can end up being FASTER than C equivalent due to lack of type > checks... >[...] > the point being made was that object orientation is not necessarely > "bloat" but leads to better written code. (not always true, but...) Code can still be fast even if it is bloated in size. Object orientation helps in writing readable and maintainable code but that is yet another issue. The code duplication we discussed here has no advantage for speed. It is quite useless duplication. >From Sven Barth: > Free Pascal is a native language. There aren't much alternatives to code duplication. Yes there is. The same container code can be reused (when possible), just like Java does. Free Pascal is native, Java generates byte-code, but that is irrelevant here. I was planning to use generics in many places in Lazarus code but now I must rethink... Lazarus executable is quite big already. Juha _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Sven Barth
to Marco van de Voort: In our previous episode, Sven Barth said: Exactly. You e.g. know that the unspecialized…
Marco van de Voort wrote 20 lines
In our previous episode, Sven Barth said: >> Afaik it was the main reason to implement generic constraints in Delphi (like >> .NET)? > > Constraints allow the compiler to infer further information on the given > types to improve e.g. type checking when parsing the generic, Exactly. You e.g. know that the unspecialized generic is already meant for reference types, from line one. > but they won't magically allow the compiler to not duplicate code (in > theory it would be possible to do something like Java's generics for cases > where the constraints are for descendants of TObject or IInterface, but in > my opinion the tradeoffs (increased compiler complexity) are not worth > it). Yeah, that is typical. If it is not used inside the compiler it is unoptimized :-) Maybe redo cclasses with generics?

That wouldn't change that much... the performance of specialized generics isn't that different from "normal" code. Also I've not yet seen anyone complain about the size of the compiler executable, only it's speed...

Let's first implement everything that we need to have full Delphi compatibilty (generic methods, constraints, inline specializations in more complicated expressions) and then we can think of optimizing the generic implementation for cases like class or interface based specializations...

Regards,
Sven

Unknown author
to Sven Barth
Sven Barth wrote 25 lines
Am 14.02.2012 22:28, schrieb Marco van de Voort: > In our previous episode, Sven Barth said: >>> Afaik it was the main reason to implement generic constraints in Delphi >>> (like >>> .NET)? >> >> Constraints allow the compiler to infer further information on the given >> types to improve e.g. type checking when parsing the generic, > > Exactly. You e.g. know that the unspecialized generic is already meant for > reference types, from line one. > >> but they won't magically allow the compiler to not duplicate code (in >> theory it would be possible to do something like Java's generics for cases >> where the constraints are for descendants of TObject or IInterface, but in >> my opinion the tradeoffs (increased compiler complexity) are not worth >> it). > > Yeah, that is typical. If it is not used inside the compiler it is > unoptimized :-) > > Maybe redo cclasses with generics? That wouldn't change that much... the performance of specialized generics isn't that different from "normal" code.

I tested that. It's about 10% slower.

Michael.

Marco van de Voort
to Sven Barth: That wouldn't change that much... the performance of specialized generics isn't that…

In our previous episode, Sven Barth said:

Show quoted text 5 lines
Let's first implement everything that we need to have full Delphi compatibilty (generic methods, constraints, inline specializations in more complicated expressions) and then we can think of optimizing the generic implementation for cases like class or interface based specializations...

Note that I mostly reacted to the sentiment it wouldn't be directly agree it is not the highest prio in the generics implementation.

I saw you recently fixed some of my bugs, I'll do a new run.

Sven Barth
to Unknown author: I tested that. It's about 10% slower. Michael.

Am 15.02.2012 14:09, schrieb

Show quoted text 35 lines
On Wed, 15 Feb 2012, Sven Barth wrote: > Am 14.02.2012 22:28, schrieb Marco van de Voort: >> In our previous episode, Sven Barth said: >>>> Afaik it was the main reason to implement generic constraints in >>>> Delphi (like >>>> .NET)? >>> >>> Constraints allow the compiler to infer further information on the >>> given >>> types to improve e.g. type checking when parsing the generic, >> >> Exactly. You e.g. know that the unspecialized generic is already >> meant for >> reference types, from line one. >> >>> but they won't magically allow the compiler to not duplicate code (in >>> theory it would be possible to do something like Java's generics for >>> cases >>> where the constraints are for descendants of TObject or IInterface, >>> but in >>> my opinion the tradeoffs (increased compiler complexity) are not worth >>> it). >> >> Yeah, that is typical. If it is not used inside the compiler it is >> unoptimized :-) >> >> Maybe redo cclasses with generics? > > That wouldn't change that much... the performance of specialized > generics isn't that different from "normal" code. I tested that. It's about 10% slower.

Compile time or runtime?

Regards,
Sven

Sven Barth
to Marco van de Voort: In our previous episode, Sven Barth said: Note that I mostly reacted to the sentiment it…
Marco van de Voort wrote 11 lines
In our previous episode, Sven Barth said: > Let's first implement everything that we need to have full Delphi > compatibilty (generic methods, constraints, inline specializations in > more complicated expressions) and then we can think of optimizing the > generic implementation for cases like class or interface based > specializations... Note that I mostly reacted to the sentiment it wouldn't be directly agree it is not the highest prio in the generics implementation. I saw you recently fixed some of my bugs, I'll do a new run.

Yes, do that please. And don't dare to find new bugs! :P :P :P

Regards,
Sven

Unknown author
to Sven Barth: Am 15.02.2012 14:09, schrieb Compile time or runtime? Sven
Sven Barth wrote 38 lines
Am 15.02.2012 14:09, schrieb > > > On Wed, 15 Feb 2012, Sven Barth wrote: > >> Am 14.02.2012 22:28, schrieb Marco van de Voort: >>> In our previous episode, Sven Barth said: >>>>> Afaik it was the main reason to implement generic constraints in >>>>> Delphi (like >>>>> .NET)? >>>> >>>> Constraints allow the compiler to infer further information on the >>>> given >>>> types to improve e.g. type checking when parsing the generic, >>> >>> Exactly. You e.g. know that the unspecialized generic is already >>> meant for >>> reference types, from line one. >>> >>>> but they won't magically allow the compiler to not duplicate code (in >>>> theory it would be possible to do something like Java's generics for >>>> cases >>>> where the constraints are for descendants of TObject or IInterface, >>>> but in >>>> my opinion the tradeoffs (increased compiler complexity) are not worth >>>> it). >>> >>> Yeah, that is typical. If it is not used inside the compiler it is >>> unoptimized :-) >>> >>> Maybe redo cclasses with generics? >> >> That wouldn't change that much... the performance of specialized >> generics isn't that different from "normal" code. > > I tested that. It's about 10% slower. Compile time or runtime?

Runtime.

Michael.

Sven Barth
to Unknown author

Am 15.02.2012 15:09, schrieb

Show quoted text 45 lines
On Wed, 15 Feb 2012, Sven Barth wrote: > Am 15.02.2012 14:09, schrieb >> >> >> On Wed, 15 Feb 2012, Sven Barth wrote: >> >>> Am 14.02.2012 22:28, schrieb Marco van de Voort: >>>> In our previous episode, Sven Barth said: >>>>>> Afaik it was the main reason to implement generic constraints in >>>>>> Delphi (like >>>>>> .NET)? >>>>> >>>>> Constraints allow the compiler to infer further information on the >>>>> given >>>>> types to improve e.g. type checking when parsing the generic, >>>> >>>> Exactly. You e.g. know that the unspecialized generic is already >>>> meant for >>>> reference types, from line one. >>>> >>>>> but they won't magically allow the compiler to not duplicate code (in >>>>> theory it would be possible to do something like Java's generics for >>>>> cases >>>>> where the constraints are for descendants of TObject or IInterface, >>>>> but in >>>>> my opinion the tradeoffs (increased compiler complexity) are not >>>>> worth >>>>> it). >>>> >>>> Yeah, that is typical. If it is not used inside the compiler it is >>>> unoptimized :-) >>>> >>>> Maybe redo cclasses with generics? >>> >>> That wouldn't change that much... the performance of specialized >>> generics isn't that different from "normal" code. >> >> I tested that. It's about 10% slower. > > Compile time or runtime? Runtime.

Then this might be because the current generic classes are written in a rather generic way (no pun intended). This might improve once constraints are implemented and generics for specific subtypes (e.g. the TFPGObjectList) can be implemented more efficiently.

Regards,
Sven

Marco van de Voort
to Sven Barth: Yes, do that please. And don't dare to find new bugs! :P :P :P Sven

In our previous episode, Sven Barth said:

Show quoted text 7 lines
> > Note that I mostly reacted to the sentiment it wouldn't be > directly agree it is not the highest prio in the generics implementation. > > I saw you recently fixed some of my bugs, I'll do a new run. Yes, do that please. And don't dare to find new bugs! :P :P :P

What does

baseimagegen.pas(130,4) Error: Global Generic template references static
symtable

Mean?

(it is at the end of a method)

Sven Barth
to Marco van de Voort
Marco van de Voort wrote 17 lines
In our previous episode, Sven Barth said: >> >> Note that I mostly reacted to the sentiment it wouldn't be >> directly agree it is not the highest prio in the generics implementation. >> >> I saw you recently fixed some of my bugs, I'll do a new run. > > Yes, do that please. And don't dare to find new bugs! :P :P :P What does baseimagegen.pas(130,4) Error: Global Generic template references static symtable Mean? (it is at the end of a method)

You are accessing a symbol that's defined in the static symtable (implementation section of the unit). Does that code compile with Delphi? If so then please report a bug...

Regards,
Sven

Jorge Aldo G. de F. Junior
to Juha Manninen: 2012/2/15, Jorge Aldo G. de F. Junior : C++ does not have generics, it has templates.…

http://theory.stanford.edu/~amitp/rants/c++-vs-c/

found the thing... its not a book and C++ has no generics but templates (for me both are the same, im no C++ programmer).

Now reading it again... The thing is that a quicksort in C can be fast only if used for one single type (at least the comparision function) while in C++ the template specialization makes the comparision function work for a greater number of types, simplifying resulting code...

2012/2/15 Juha Manninen :

Show quoted text 39 lines
2012/2/15, Jorge Aldo G. de F. Junior : > i once read a textbook about generics (C++ generics) showing how C++ C++ does not have generics, it has templates. Templates syntax is complex, you can do actual programming with it. IMO, using all its capacity leads to over-engineered and unreadable code. I read about a plan to add Java style generics syntax to C++, in addition to templates. I guess it will not happen. C++ has enough syntax already. > code can end up being FASTER than C equivalent due to lack of type > checks... >[...] > the point being made was that object orientation is not necessarely > "bloat" but leads to better written code. (not always true, but...) Code can still be fast even if it is bloated in size. Object orientation helps in writing readable and maintainable code but that is yet another issue. The code duplication we discussed here has no advantage for speed. It is quite useless duplication. >From Sven Barth: > Free Pascal is a native language. There aren't much alternatives to code duplication. Yes there is. The same container code can be reused (when possible), just like Java does. Free Pascal is native, Java generates byte-code, but that is irrelevant here. I was planning to use generics in many places in Lazarus code but now I must rethink... Lazarus executable is quite big already. Juha _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marco van de Voort
to Sven Barth: You are accessing a symbol that's defined in the static symtable (implementation section…

In our previous episode, Sven Barth said:

Show quoted text 9 lines
> symtable > > Mean? > > (it is at the end of a method) You are accessing a symbol that's defined in the static symtable (implementation section of the unit). Does that code compile with Delphi? If so then please report a bug...

I was still isolating at the end of the working day, so that will be later. tomorrow, I'm maybe not in the office, so that will be friday.

The static symtable bit might be simple constant values. The structure is more or less

type
      TgenImage<T>=Class(TBaseImage) // tbaseimage is not generic
                     type
                       reft = ^T;
                     private
                       allocptr : reft;
                     public
	               procedure alloc; override; // is virtual abstract in baseimage
                     end;
implementation
const alignvalue =16;  // must be power of two
      alignmask  =alignvalue-1;
procedure tgenimage<t>.alloc;
var localptr : reft;
begin
  (ptrint(allocptr) and alignmask)];
end;

(to align an allocation to a certain boundery for SSE use, code from memory, it is the pattern, not an exact formula to do that)

While isolating, the error seemed to randomly disappear and popup. But that could also be several "inline" methods, which have now been removed for isolation purposes.