Recent

Author Topic: Which unit should I use?  (Read 1140 times)

guest64953

  • Guest
Which unit should I use?
« on: December 07, 2019, 03:09:11 am »
I want a unit provide List data structure and to some extent, Map too. There are so many of units provide these data structure, e.g: FCL, Generics.Collection, FGL... Which unit should I use?  :)

jamie

  • Hero Member
  • *****
  • Posts: 3669
Re: Which unit should I use?
« Reply #1 on: December 07, 2019, 03:21:31 am »
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.
 
The only true wisdom is knowing you know nothing

dsiders

  • Sr. Member
  • ****
  • Posts: 380
Re: Which unit should I use?
« Reply #2 on: December 07, 2019, 04:20:51 am »
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.

Are you trolling me?  >:(

locate maps.pp

Who's trolling who?
Lazarus 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

guest64953

  • Guest
Re: Which unit should I use?
« Reply #3 on: December 07, 2019, 04:24:31 am »
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.

Are you trolling me?  >:(

locate maps.pp

Who's trolling who?

The maps.pp of LazUtils? Sorry, he wrote in uppercase and didn't point me to where the unit is so I think it must be troll  :-[

p/s: He should provide at lease one link like this https://lazarus-ccr.sourceforge.io/docs/lazutils/maps/tmap.html. Anyway, it's my fault. Sorry everyone  :(

guest64953

  • Guest
Re: Which unit should I use?
« Reply #4 on: December 07, 2019, 04:34:52 am »
You are in luck, there just happens to be a unit calls MAPS !

 Last time I looked at it, it looked like it could need some clean up but its used deep in the heart of a lot of code I guess.

Sorry for misunderstand your post  :( About List, which unit should be used? Thanks  :)

jamie

  • Hero Member
  • *****
  • Posts: 3669
Re: Which unit should I use?
« Reply #5 on: December 07, 2019, 10:55:18 pm »
it depends on the type of data you are manipulating.

Also, are you looking for viewing options of this data, too ?
The only true wisdom is knowing you know nothing

PascalDragon

  • Hero Member
  • *****
  • Posts: 2275
  • Compiler Developer
Re: Which unit should I use?
« Reply #6 on: December 08, 2019, 11:48:49 am »
Sorry for misunderstand your post  :( About List, which unit should be used? Thanks  :)
In general you should go with Generics.Collections nowadays. Due to them being generics they allow for typesafe containers and thus less programmer errors due to incorrect casts that can happen with Classes.TList for example. They also don't require you to implement special operators for comparison as the FGL ones require.

FGL should be used if you want typesafe containers on the one hand, but are also constrained to small code sizes (e.g. for embedded platforms).

The containers in Classes are mainly useful if you want to store multiple different types of objects (e.g. TObjectList if you'll store a TStringList and a TComponent in the same list, cause using TObjectList<TObject> from Generics.Collections is a bit of an overkill...)

guest64953

  • Guest
Re: Which unit should I use?
« Reply #7 on: December 09, 2019, 03:46:15 pm »
Sorry for misunderstand your post  :( About List, which unit should be used? Thanks  :)
In general you should go with Generics.Collections nowadays. Due to them being generics they allow for typesafe containers and thus less programmer errors due to incorrect casts that can happen with Classes.TList for example. They also don't require you to implement special operators for comparison as the FGL ones require.

FGL should be used if you want typesafe containers on the one hand, but are also constrained to small code sizes (e.g. for embedded platforms).

The containers in Classes are mainly useful if you want to store multiple different types of objects (e.g. TObjectList if you'll store a TStringList and a TComponent in the same list, cause using TObjectList<TObject> from Generics.Collections is a bit of an overkill...)

How to install Generics.Collections? Is it shipped with Lazarus by default?  :)

guest64953

  • Guest
Re: Which unit should I use?
« Reply #8 on: December 09, 2019, 03:50:11 pm »
it depends on the type of data you are manipulating.

Also, are you looking for viewing options of this data, too ?

I just want something similar to Java ArrayList or C++ vector. Indeed, I want an dynamic array without having to setlength and this array just grow up when more data is added. The data itself, currently, just simple integer or double  :)

Handoko

  • Hero Member
  • *****
  • Posts: 3869
  • My goal: build my own game engine using Lazarus
Re: Which unit should I use?
« Reply #9 on: December 09, 2019, 04:12:43 pm »
How to install Generics.Collections? Is it shipped with Lazarus by default?  :)

As far as I know Generics already included in recent versions of Free Pascal. Read more:
https://wiki.freepascal.org/Generics

PascalDragon

  • Hero Member
  • *****
  • Posts: 2275
  • Compiler Developer
Re: Which unit should I use?
« Reply #10 on: December 10, 2019, 09:33:19 am »
How to install Generics.Collections? Is it shipped with Lazarus by default?  :)
With FPC 3.2 it's part of the packages provided by FPC. For older versions I think Lazarus provides an implementation.

How to install Generics.Collections? Is it shipped with Lazarus by default?  :)

As far as I know Generics already included in recent versions of Free Pascal. Read more:
https://wiki.freepascal.org/Generics
We're not talking about generics in general, but a specific class library that utilizes generics.

 

TinyPortal © 2005-2018