Recent

Author Topic: Free Pascal and others...  (Read 13932 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14211
  • Probably until I exterminate Putin.
Re: Free Pascal and others...
« Reply #15 on: May 12, 2017, 10:09:07 am »
I've just checked KSP's forum, it seems garbage collection really causing headache for them.

They probably have their programming paradigm wrong.
There's nothing inherently wrong with GC as long as you are aware of its limitations:
Hence Java programmers tend to use loads of object pooling. They should do the same.
GC is specifically unsuited for speedy creation and destruction - or lack thereof :D - of many small objects.
But that can often be mitigated.

Also, in e.g. Java the GC can be finely configured. I am not aware that is possible in C# at least not to the same extend
« Last Edit: May 12, 2017, 10:11:13 am by Thaddy »
Specialize a type, not a var.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Free Pascal and others...
« Reply #16 on: May 12, 2017, 10:31:54 am »
I never use GC but it won't harm doing some research about it. I found an article suggesting how to properly use garbage collection on Unity - the software used to create KSP.

Maybe off topic but some might interested to know, here I quote the texts:

Quote
GameObject instantiate and destroy

If you make frequent calls to instantiate and destroy throughout the lifetime of your game or app, this could affect the GC substantially. Try to create a pool of game objects at the start of your game, which you can then enable and disable throughout your game.

GetComponents

This might be used in tandem with interfacing to create a modular way of having your game objects interact with each other. A collection of components is generated and returned when GetComponents is called, and once this collection is no longer needed, it triggers the GC. Make sure you profile its use and determine if it's acceptable. You might have to develop another type of architecture to support your game object interaction that does not depend on GetComponents.

String concatenation

This is very common for C# developers. When you concatenate strings (“Hello” + “World”) you are creating a new string object. If you do this each frame, you are adding a good amount of unnecessary GC work when you could be caching or concatenating without +.

Source:
https://www.pluralsight.com/blog/software-development/unity-tips-and-tricks

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Free Pascal and others...
« Reply #17 on: May 12, 2017, 10:41:42 am »
I've just checked KSP's forum, it seems garbage collection really causing headache for them.

They probably have their programming paradigm wrong.
There's nothing inherently wrong with GC as long as you are aware of its limitations:
Hence Java programmers tend to use loads of object pooling. They should do the same.
GC is specifically unsuited for speedy creation and destruction - or lack thereof :D - of many small objects.
But that can often be mitigated.

Pretty much. And the mitigations are much the same, and in much the same places as manual allocation. Which defeats the purpose quite a bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14211
  • Probably until I exterminate Putin.
Re: Free Pascal and others...
« Reply #18 on: May 12, 2017, 11:01:08 am »
To a large extend: agree. But object pooling is a technique that can also speed up non-gc code considerably (either arc/interfaces or manual). Apart from speed, constant or predictable memory pressure is also a desirable factor.
« Last Edit: May 12, 2017, 11:06:59 am by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Free Pascal and others...
« Reply #19 on: May 12, 2017, 11:31:56 am »
To a large extend: agree. But object pooling is a technique that can also speed up non-gc code considerably (either arc/interfaces or manual). Apart from speed, constant or predictable memory pressure is also a desirable factor.

Yup. I already pool images since D6 times, when I first encountered the heap fragmentation phenomenon.   Pools are generic now, there is a pool-factory split. IIRC the code is openly available even, in my opengl demo.

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Free Pascal and others...
« Reply #20 on: May 13, 2017, 10:46:13 am »
TopSpeed Modula2,
 
32-bit being the main motivator, since increasing amounts of work went in my old app working around memory limitations. (64k per structure, EMS/XMS etc).  Commercial 32-bit M2, already not a primary choice due to student finances and no sitelicenses, had no real non dos/windows options (and I wanted Linux/BSD in due time), so I ended up with FPC.

The lessons I learned from the M2 period were that language purity is overrated, specially when taken to extremes, and not having a(ny) community, and having to do everything by yourself is tiring.
Yes, I'd forgotten that (never got TopSpeed), I just gave up and went back to Pascal.  The bit about libraries and community can't be overemphasized, some good stuff has died out for that reason. 

Of course I/O was a big problem in the original Writh definition of Pascal (like it was a major pain, I first used Pascal c1981 on a main frame) trying to just write a sting to standard I/O was confusing especially for a beginner (I'd already learned several languages by then so it was just awkward for me, but for most students in that class it was like their first intro to programming after BASIC), but that got fixed, and I'm sure M2s shortcomings would have too, but we are where we are and FPC/Lazarus is really a darn good language, I can produce debugged code faster than anything else in it and if M2 had become dominant instead, that's probably what I'd be saying about it.

@OP:
I just looked and I see there is a free version of ADA, anyone interested in Pascal like languages should check it out:
https://en.wikipedia.org/wiki/Ada_%28programming_language%29
or here:
http://www.getadanow.com/
which is GNU 3 license
Learn it then maybe get a job with the US DOD ;) (no I didn't download it got enough on my plate).
This was an attempt actually to consolidate a lot of languages but it has a lot in common with Pascal (and ALGOL).  Get a basic feeling for it (no pun intended) here:
https://en.wikipedia.org/wiki/Ada_%28programming_language%29
It was written with concurrency in mind and built into the language so it might be useful for that.  But implement some pragmas and there goes all the safety features :).

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Free Pascal and others...
« Reply #21 on: May 13, 2017, 11:18:30 am »
String concatenation
This is very common for C# developers. When you concatenate strings (“Hello” + “World”) you are creating a new string object. If you do this each frame, you are adding a good amount of unnecessary GC work when you could be caching or concatenating without +.
[/quote]
Which would explain why they told add-on makers not to do that :).  I actually have never noticed the GC, but I have a pretty powerful computer and I'm not into building huge space ships or aircraft with 300+ parts, nor do I use very many add-ons (some use hundreds I use three or four).  Also they went 64bit a while back so it's can have a lot more memory available (though for some reason Steam defaults it to the 32bit version on 64bit OSes--yes Mac and Linux versions too). And they did do a good job of mitigating it though it can still be a problem.  Given the original program was going to be sort of a design your own rocket but only 2D like old lunar lander, it's really a pretty amazing program, highly recommended and you can learn a lot of rocket science if you want or just enjoy watching things go boom.  The original developer left last year (after 5 years I suspect he got tired) but they are coming out with a localization update and their first DLC is in the works.  Given it's in C# ;) and forced a game engine to do new things (they had a hard time doing spheres in the early days) it's pretty nice. 

Sorry going so far off topic!  But it's one of the best games I've ever played (I'm not much of a FPS type, more a 4x and flight sim type).  It does have short comings, notably the graphics could do with a spiff up (though there are some nice add-ons for that), but what large software project doesn't?  Wish I'd thought of it.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Free Pascal and others...
« Reply #22 on: May 13, 2017, 01:53:06 pm »
That game looks interesting, I have checked the information on the web. I play games but not those eye candy -styled nor finger tired mouse clicking games. I have finished Civilization 2, FreeOrion and now playing Oolite. KSP now is in my will play list.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Free Pascal and others...
« Reply #23 on: May 15, 2017, 10:43:47 am »
String concatenation

This is very common for C# developers. When you concatenate strings (“Hello” + “World”) you are creating a new string object. If you do this each frame, you are adding a good amount of unnecessary GC work when you could be caching or concatenating without +.
And that is why Java has the StringBuilder class, which allows for tight loop string concatenation and insertion without creating tons of new String objects. I believe Delphi has such a class too - for iOS usage (and their NextGen compiler). I would be surprised if C# doesn't have something similar.

Bottom line, developers should know what classes and functionality is available for each language. Learning a language syntax is easy, but learning the associated frameworks is what takes so much time.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Thaddy

  • Hero Member
  • *****
  • Posts: 14211
  • Probably until I exterminate Putin.
Re: Free Pascal and others...
« Reply #24 on: May 15, 2017, 02:46:49 pm »
Yes, C# has a stringbuilder class. I thought we also have something similar around somewhere.
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Free Pascal and others...
« Reply #25 on: May 15, 2017, 09:00:36 pm »
String concatenation

This is very common for C# developers. When you concatenate strings (“Hello” + “World”) you are creating a new string object. If you do this each frame, you are adding a good amount of unnecessary GC work when you could be caching or concatenating without +.
And that is why Java has the StringBuilder class, which allows for tight loop string concatenation and insertion without creating tons of new String objects. I believe Delphi has such a class too - for iOS usage (and their NextGen compiler).

NO, it was introduced for Delphi.NET that inherited the immutable strings from the CIL. The native variant was only for compatibility.

dracon

  • New Member
  • *
  • Posts: 18
Re: Free Pascal and others...
« Reply #26 on: May 15, 2017, 10:29:28 pm »
May add yet another question?

Are there any important learning resources regarding FPC?

The spirit of the question concerns a general (but complete) outlook of the language.

Thank you all.

 

TinyPortal © 2005-2018