The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for the ‘Delphi’ Category

TInterlockedHelper for Delphi interfaces: Spring.Reactive.pas

Posted by jpluimers on 2020/02/25

Reminder so self: [WayBacksglienke / Spring4D / source / Source / Reactive / Spring.Reactive.pas — Bitbucket fragments:

type
  TInterlocked = SyncObjs.TInterlocked;
  TInterlockedHelper = class helper for TInterlocked // TODO: move to Spring.pas
    class function CompareExchange<T: IInterface>(var Target: T; const Value, Comparand: T): T; overload; static;
    class function Exchange<T: IInterface>(var Target: T; const Value: T): T; overload; static;
  end;

{$REGION 'TInterlockedHelper'}

class function TInterlockedHelper.CompareExchange<T>(var Target: T;
  const Value, Comparand: T): T;
begin
  Result := Default(T);
  PPointer(@Result)^ := CompareExchange(PPointer(@Target)^, PPointer(@Value)^, PPointer(@Comparand)^);
  if PPointer(@Result)^ = PPointer(@Comparand)^ then
  begin
    if Assigned(Value) then
      Value._AddRef;
  end
  else
    if Assigned(Result) then
      Result._AddRef;
end;

class function TInterlockedHelper.Exchange<T>(var Target: T;
  const Value: T): T;
begin
  Result := Default(T);
  PPointer(@Result)^ := Exchange(PPointer(@Target)^, PPointer(@Value)^);
  if Assigned(Value) then
    Value._AddRef;
end;

{$ENDREGION}a

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Delphi memory allocators and configuration notes in multi-threaded environments with high allocation/deallocation rates

Posted by jpluimers on 2020/02/20

From an interesting discussion at [Archive.is/WayBack] FaceBook: Delphi developer thread by Jarto Tarpio with some measurements by Jarto Tarpio and André Mussche.

  • Manipulation of strings and lists in Delphi have high memory allocation/deallocation rates, so HTTP related services with high call rates are affected more than regular services
  •  FastMM:
    • conditional defines that can help are NeverSleepOnThreadContention, UseSwitchToThread, and UseReleaseStack then measure.
    • has one huge advantage: It’s very, very good at keeping memory fragmentation at bay
    • default settings are for applications that use lots of CPU, but have no really high memory allocation/deallocation rates
    • has very good debugging facilities
    • Under FullDebugMode address space is never released back to the operating system so once the address space has been exhausted there is very little room to manoeuvre.
  • TCMalloc:
    • is very good at multi-threaded memory management with high allocation/deallocation rates
    • needs to be persuaded to releases memory to the OS:
      it only releases to the system under two occasions: Freeing another part of the memory, or asking it to release all parts marked as freed.

    • has no debugging facilities

The differences make it a challenge to integrate in your development and deployment process: because of the debugging facilities, you’d like FastMM in all your environments, but TCMalloc in multi-threaded environments with high allocation/deallocation rates.

One possibility is to have your CI environment deliver both in all stages, run all tests on both, then choose the final one depending on your run-time configuration.

That gives a burden on configuring your Continuous Integration, but the gain might outweigh this cost.

Relevant links from the Facebook thread:

–jeroen

Posted in Delphi, Development, FastMM, Software Development | 5 Comments »

Does anyone knows a existing implementation of bcrypt or scrypt for delphi?

Posted by jpluimers on 2020/02/19

For my link archive: [WayBack] Does anyone knows a existing implementation of bcrypt or scrypt for delphi? – Fabian S. Biehn – Google+:

–jeroen

Posted in Delphi, Development, Encryption, Power User, Security, Software Development | Leave a Comment »

Some interesting Delphi MVVM posts…

Posted by jpluimers on 2020/02/18

Via [WayBack] We kick off a week of MVVM with an introduction of the Model-View-ViewModel pattern and how data binding is used to realize it. – Erik van Bilsen – Google+:

I wrote (and gave a few conference talks) about DSharp before, so the above is very interesting.

–jeroen

References:

Posted in Delphi, Development, Software Development | 2 Comments »

Happy Delphi 25th anniversary: follow hash tags #Delphi25 and #Delphi25th

Posted by jpluimers on 2020/02/14

I wish I could have prepared something more substantial for the 25th Delphi birthday.

Alas: life has been tough (see below), so please keep an eye on these search terms, hash tags and start posts from past Delphi team key members:

Search term: “Interview with Anders Hejlsberg and Chuck Jazdzewski #Delphi25th”; highlights from it:

  • “The men in this video are responsible for an incalculable amount of software, in one way or another. It boggles the mind to think about their impact on our industry.
    I know, right? If you aren’t using software they were directly involved in, then you are using software inspired by their software.”
  • Delphi 1 being postponed 6 months to ensure the visual designer and live data worked properly; the side effect was top notch quality of other product areas
  • Shipping the RTL and VCL code was very important
  • “If it was done right, we wouldn’t have a job” – had me truly LOL! It is so true! The Windows API was powerful, but hard to use – slightly better today, but still Delphi run circles around any other UI for Win32 tool – VB included.
  • Method Pointers changed the perspective of a lot of software development, even outside the Delphi world
  • Peter Sollich working on the compiler (Wish Peter Sollich was mentioned more; he was instrumental to the compiler.)
  • Garbage Collection is beautiful, but adds a truckload of complexity interfacing to the non-garbage collected underlying Windows API
  • The power of the VCL component model working irrespective of the state (having a Windows Class, Window Handle, etc) of the underlying Windows controls
  • The automatic recreation of underlying controls when certain component properties change is still important today on the supported platforms, for instance when switching from landscape to portrait mode
  • Reference counting (which was already with large strings) only gets you so far, as it can leave isolated islands that never get collected; mark and sweep was hardly used in any other environment
  • The beta/field-test/code names (like Delphi, Wasabi, Mango) depended on the group of people they were sent to
  • “Very important was that the Delphi 2.0 compiler and VCL was long underway before Delphi 1 was released. That made the transition from Win16 to Win32 so much easier.
    Yes, and really interesting in terms of strategic planning”
  • “I think Monet was ObjectVision 1.0 I think -and ObjectVision 3.0 was bundle with TurboC as I remenber it – I was PM on that in Scandinavia. :)”
  • Chuck is now working at Google on a new framework for Android Development called “Compose”.
  • Anders worked for a short while on Visual J++, then on C# and .NET, then adding TypeScript, and helped Microsoft move from inward oriented company to opening up to open source. He now spends his time committing code to github (github.com/ahejlsberg) because he wanted to go back to coding instead of managing.
  • “If playback doesn’t begin shortly, try restarting your device.” It stopped playing as soon as you switched to YouTube.
    Sorry. Must be a network issue. We will send out a replay link.”
  • “The first time I used Pascal, it was Compas Pascal – also written by Anders Heijlsberg. Now he is behind C# and TypeScript – he surely is leaving a major mark on the runestones of software development!”
  • DogFood is important; Turbo Pascal and Delphi were among the first; C# and TypeScript now do this too.
  • “Will the anniversary page Delphi.embarcadero.com be available in future also ?
    Yes, that is the plan. We made it Delphi.embarcadero.com instead of Delphi25. so we can keep it around. Plus we have more content comming on there.”
  • The Delphi compiler version actually started at 1.0 for Turbo Pascal 1.0
  • “Official MS Windows Me image for Virtual Box can be found at https://archive.org/details/win_me_archive_vdi
  • DavidI: Special respect to my “Twin separated at birth” Charlie Calvert for training the world on Delphi !!!
  • [WayBack] (PDF) Borland Software Craftsmanship: A New Look at Process, Quality and Productivity
    A:This is a great paper. By coincidence I actually saw it less than two days ago!
  • “Don’t forget Cary Jensen, I have met him at the first Delphi courses in Amsterdam ~24 years ago. I hope he is well!”
  • “Don’t forget InterBase has been there all the time along the way too! And still going strong, and across all the same target platforms!”
  • “How about a line profiler built-in, rather than having to purchase and install AQTime?”
  • “This site has VirtualBox virtual machine images for all legacy versions of Windows, including “Window 3.1” … http://virtualdiskimages.weebly.com/virtualbox.html
  • “I agree with the very useful feature of being able to make Windows versions of the mobile apps. This is one, that is being used exactly for that… multipurpose. https://play.google.com/store/apps/details?id=com.danvaegt.SmartWeighClient

A few of my recent tweets:

 

Delphi 25th pages

Read the rest of this entry »

Posted in Delphi, Development, Software Development | Leave a Comment »

Reminder to self: be aware of implicit setup/tear down code in methods

Posted by jpluimers on 2020/02/13

If a part of a method requires implicit setup/tear-down code (for instance when using managed types like arrays, strings, etc), especially in rarely taken execution paths, then consider putting that code in a separate method.

I bumped into this recently, and found out it does not just hold for Delphi, it can happen in other languages too.

A Delphi example I found back is this one: [WayBackDelphi Corner Weblog: Speed problems caused by code that never ran.

The problem with Delphi is that the language does not have local scope (variables are at the start of the method) which means the penalty is for the full method.

I bumped into this in C# where a piece of legacy code had the variables declared away from the block where they finally were used.

This historically grew, because originally they were used in more placed of the code.

The refactoring limiting the scope just never put the declaration close to the usage hence violating the proximity principle.

Via: [WayBack] Ouch! Code that doesn’t get executed can still cause other code in the same procedure to become much slower. Of course, in retrospect, once you know the… – Thomas Mueller (dummzeuch) – Google+

–jeroen

Posted in .NET, Delphi, Development, Software Development | Leave a Comment »

Delphi desktop settings: .DST naming limitations and content similarity to .DSK files

Posted by jpluimers on 2020/02/12

Based on [WayBack] Bummer, cannot save a Delphi desktop named “Default Layout – right 3/4” – at load this one seems to be restored, but the list does not contain that entry. – Jeroen Wiert Pluimers – Google+:

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Catch Me If You Can: LLVM back-end cannot catch all exceptions

Posted by jpluimers on 2020/02/11

[WayBack] Catch Me If You Can:

the LLVM backend cannot return from a hardware exception (like AV) if the hardware exception is raised directly within a try...except block. It can only safely return if there is a function (method) call within the try...except block.

Via and by [WayBack] Dalija Prasnikar – Google+

–jeroen

Posted in Delphi, Development, Software Development | 1 Comment »

Is there a keyboard shortcut to go to the next/previous compiler error in the current …

Posted by jpluimers on 2020/02/11

Via: [WayBack] Is there a keyboard shortcut to go to the next compiler error in the current source file? – Jeroen Wiert Pluimers – Google+:

Primož Gabrijelčič:
Alt-F7, Alt-F8 IIRC

And indeed, it is sort of documented as of Delphi 2007 for “Message View”, but appears to be a much older shortcut:

I also completely forgot the compiler output is indeed a “Message View”.

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Delphi Berlin and up without disabled Castalia: Use Ctrl+W to select content in the IDE code editor. Place your curso…

Posted by jpluimers on 2020/02/06

If you have enough guts to keep Castalia enabled and have Delphi Berlin or higher, then you can use this shortcut:

[WayBack] Tip: Use Ctrl+W to select content in the IDE code editor. Place your cursor some random piece of code, preferably deep in code that have nested block… – Lars Fosdal – Google+

–jeroen

Posted in Castalia, Delphi, Development, Software Development | Leave a Comment »