Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Generic collections

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Generic collections

    We'll need some collection classes and algorithms which will be used everywhere in engine.
    Requirements:
    1. implementation of at least List, Map (dictionary) and sorting
    2. work with different types, including primitive ones (non classes)
    3. high performance
    4. type safe
    5. without code duplication

    Class/interface based approaches are not comply with requirement #2 and #3.
    Pointer-based implementations conflicts with requirement #4.
    I know two remaining solutions:
    1. Generics.
    + intended to solve this problem exactly
    - not supported by Delphi 7 and FPC 2.6.2
    2. include-based template approach
    + max performance and flexibility
    + support of D7 and FPC 2.6.2
    - only one instantiation of each template per unit
    - hard to read and support template code (does not apply to code using the templates)

    I've implementation of the second approach:
    https://github.com/casteng/base/tree/dev/template
    You can see what it looks like.

    We can drop support of D7 and FPC 2.6.2 and go with generics.
    What do you think guys?

  2. #2
    Unacceptable. One of the main reasons we are doing this, is because we want to support every version since D7 and all fpc. Another reason is that generics make your app increase in size every time you use another instance of the same library for another purpose. What I was thinking, is to implement some kind of double linked list or btree using pointers (maybe both), advantage we can put anything inside, it's faster than anything, small footprint.

  3. #3
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25
    Personally I like generics. I find them easy to use and a perfect fit for this situation. As for for the support of D7 and FPC 2.6.2 I understand the support for D7 but FPC is free, anyone can get a newer version. This shouldn't be a factor when deciding how to implement. Just my 2 cents.

  4. #4
    pitfiend, pointer-based approach is not type safe (remember why we using Pascal?) and has poor data locality, and therefore performance.
    So we need to implement collections for each type. Good news that size increase is negligible in case of a few collections and algorithms.

    gasdeveloper, the problem with generics is compatibility between Delphi and FPC syntax. I don't know exactly which FPC version is ok for this. Generics with FPC syntax are supported from FPC 2.2.

  5. #5
    Quote Originally Posted by Mirage View Post
    pitfiend, pointer-based approach is not type safe (remember why we using Pascal?) and has poor data locality, and therefore performance.
    So we need to implement collections for each type. Good news that size increase is negligible in case of a few collections and algorithms.
    Can't agree on that. One of the most important language features is going to be left just because we use Pascal? A well designed structure and helpers could solve any of our needs. I also think that we must build real objects and not classes, they are faster, have inheritance and also very small footprint. And yes, I am an old school developer.

  6. #6
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Would it not be possible to get some polls of who is using which FPC versions and decide then? Personally, I think that if we're making a new engine for the future, it'd be a contradiction to not use some newer features for the sake of backwards compatibility. A couple years down the line, I don't think it'll be very likely we'll alienate people from the engine on account of them not being able to get their hands on a copy of delphi newer than 7 or fpc 2.6.2 (I think it was?).

    At a glance it looks like it complicates things and almost causes us to work around a feature just to provide support for what is already considered old software (delphi 7 has been around as long as I can remember) which is already pseudo-irrelevant and will only become more so as times goes on.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  7. #7
    they are supposed to be compatible in Delphi mode ( {$mode Delphi} )

    I still vote for templates with include files though
    le programmeur

  8. #8
    maybe use whichever is faster in engine internals and leave choice on using generics to engine 'end' users?
    imo modern engine should run on many platforms out of the box and expose scripting language as main way of coding the game.
    ability to mess with the source code is a big advantage but not everyone would need or want that

  9. #9
    I vote for include-based template approach
    le programmeur

  10. #10
    Free Pascal has several Pascal syntax modes: FPC, TurboPascal, Object Free Pascal, Delphi and Mac Pascal (whatever it is). Maybe something else I forgot to mention. Objective-C maybe. In Object Free Pascal mode generics are incompatible with Delphi because apparently Free Pascal developers invented their own syntax for generics; however in Delphi syntax mode Free Pascal generics syntax conforms to Delphi generics syntax (more or less). While Free Pascal might not support latest additions to generics introduced in Delphi, it should be able to compile simplier cases; so in general it should be possible to compile same source code with generics both in FreePascal and Delphi.
    Most likely, Free Pascal does not support generic constraints: this TIntfListGenericType<T: IInterfaceList> thing

    le programmeur

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •