Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 02/17/21 in all areas

  1. David Heffernan

    Quickly zero all local variables?

    I can't believe that anybody would use such code in real programs. Wouldn't it just be better to initialise your local variables?
  2. Sorry, can't agree. There are many good reasons to rework code, and performance is just one of them. When I was learning to code, many years ago, a colleague advised "first make it work, then make it fast." Performance optimization should be done because of performance issues, not simply to see whether you can buy another 10% improvement in a routine which doesn't affect user perception at all. Good reasons to rework code include clarity, reduced coupling, better organization of modules, improving naming, adding documentation of the need for the actions in routines. Seeking to optimize every routine in a program is a waste of energy, and a needless cost. Justifiable for a hobby, or in open-source, perhaps, but not in commercial work.
  3. Fr0sT.Brutal

    Undocumented language enhancements

    "Static variables" inside procedures function Counter: Integer; {$J+} const I: Integer = 0; {$J-} begin I := I + 1; Result := I; end; When you declare a const with a type, Delphi allocates memory for the constant. The program can change the value of the “constant,” just as though it were a variable. The difference between a typed constant and a local variable is that a typed constant in a subroutine keeps its value across subroutine calls. If you disable the $WriteableConst directive, you can prevent any assignments to a typed constant, thereby making the constant truly constant. There is no substitute for typed constants in a subroutine, though, so disable $WriteableConst with care. Disable only specific constants whose value you want to protect, and do not disable this directive globally in a project or an entire file. Short init of record constants type TR = record a: string; b: string; end; Const TR_Empty: TR = (); Const TR_A: TR = (a: 'foo'); (not undocumented but non-obvious ones)
  4. Undocumented intrinsic routines Undocumented Delphi routines Undocumented Delphi record alignment directive Just to name a few. I know there are other sites that document more, I just don't have the time to hunt them down.
  5. As a developer improves, (hopefully) the developer can write more optimized code in about the same amount of time as they used to write less optimized code. Knowing when to use a TStringBuilder instead of concatenating strings for example, and knowing when doing so will make a difference. Recognizing the use cases and intuitively selecting the data structure most suited for it. etc. Often, it does not take much longer to write faster code than slower code, if you know what you are doing. Beyond that, I would not do much optimization until you had specific use cases that were performing badly. Then, you need to profile those use cases. Once those have been profiled, sometimes it is obvious what to tackle, sometimes sadly its death by 1000 cuts. But I do not not think premature optimization is BS. It happens all the time and is generally a waste. Until you have specific use cases it does not make much sense to make much efforts to optimize, beyond what you are naturally able to do based on your skill level. You can spend hours optimizing some data structure that was never going to be a problem in the first place.
  6. Stefan Glienke

    Quickly zero all local variables?

    Isn't it usually Sheldon who comes up with ridiculous stuff just to win an argument?
  7. Dalija Prasnikar

    How do you identify bottleneck in Delphi code?

    Problem with quoting is that usually it is either cut down to the point of being misquoting or it requires more context to be properly understood. Knuth is spot on, and if you read more besides the "Premature optimization is root of all evil" phrase, it will be more clear to you what it really means. https://softwareengineering.stackexchange.com/questions/80084/is-premature-optimization-really-the-root-of-all-evil
  8. Der schöne Günther

    Quickly zero all local variables?

    That may be true in your case, but zeroing a local variable "just in case" for a method that gets called over and over defenitely is a performance hit.
  9. Two new zips for Win32 and Win64 versions of OpenSSL 1.1.1j can now be downloadable from the Wiki at: http://wiki.overbyte.eu/wiki/index.php/ICS_Download or https://www.magsys.co.uk/delphi/magics.asp . The latest 1.1.1 DLLs are also included in the ICS distribution SVN and overnight zip. Beware SVN and the overnight zip for forthcoming V8.66 include is a major clean-up of OpenSSL functions, and may require end user application changes if low level OpenSSL functions have been used, hopefully very rarely. All OpenSSL functions have been renamed to their original names removing ICS f_ prefix so they now have the original OpenSSL names for commonality with other Delphi applications. OpenSSL 1.0.2 and 1.1.0 ceased security fix support over 12 months ago, so ICS now only supports 1.1.1, with 3.0 support due in the next few months. This removes a lot of legacy code and functions, and several old ICS functions needed for backward compatibility. Two components only used for 1.0.2 have been removed, TSslStaticLock and TSslDynamicLock which may give an error loading forms, until they are removed. SslContext SslOptions is now ignored, use SslOptions2 instead which has more modern options. Can not remove SslOptions because it's saved on too many DFMs. Most modern applications should not be using SslConext, but IcsHosts for servers or high level client components like TSslHttpRest. If your application needs to use 1.0.2, you must keep using V8.65 or earlier. Angus
  10. Sometimes I come across some delphi language enhancements that are undocumented or are poorly documented. In the last few years docwiki has improved a lot, but there are still undocumented cases, such as accessing an item in an array just by declaring a property, without any method: TipGeolocation = record private FCoordinates: array[0..1] of Double; public property Latitude: Double read FCoordinates[0] write FCoordinates[0]; property Longitude: Double read FCoordinates[1] write FCoordinates[1]; end; Share here any enhancements to the delphi language that you have discovered but are not documented.
  11. Hi All I have been steadily working away on my package manager project - the latest update includes compile on install support. https://github.com/DelphiPackageManager/DPM When a package is first installed, it is automatically compiled (if the package spec has that support enabled) and then the project references the compiled version of the package. This speeds up builds on your own projects, since you are not compiling the dpm package sources each time. As an extreme example of this, the DPM build process (building for 12 versions of delphi!) previously took 13 minutes on my build server, after installing the latest dpm and running 2 builds (the first one compiled the packages), the build time is down to 2 minutes! Much of that speed up comes from the fact that older versions of delphi are quite slow at building Spring4D. I encourage everyone to check it out and provide feedback where possible. To get started using DPM, download the latest release from here : You will need to configure a package feed (folder) and download some packages - see the Getting started page Most of my open source projects have package files available under the releases tab on github - https://github.com/vsoftTechnologies/ I have also added a mirror project for Spring4D on github so that I could publish packages (bitbucket doesn't support that) - https://github.com/VSoftTechnologies/Spring4DMirror Same for JsonDataObjects - Andreas ignored my pull request for over a year so I closed it and just forked the project - https://github.com/VSoftTechnologies/JsonDataObjects I'm still working on getting design time packages loaded.. need to get proper project group support going first. Previous updates here :
  12. David Heffernan

    Quickly zero all local variables?

    Why would anybody use code that does nothing? You call a procedure passing parameters by value. Then that procedure modifies those parameters. You've basically done this: procedure Foo(Value: Integer); begin Value := 0; end; I don't think it takes a genius to see that this is pointless. Furthermore, were your function able to do what you think it can, it's still useless. Who the heck is going to call a procedure passing a list of variables, to have that procedure set them to zero? You'll just set them to zero at the call site using the assignment operator. You really think people are going to write: prcInitItPlease([lMyVarLocalThiProc, lMyOtherVarLocal]); (which does not and cannot work as noted above) rather than lMyVarLocalThiProc := 0; lMyOtherVarLocal := 0; Honestly, this thread is mind boggling!
  13. David Heffernan

    How do you identify bottleneck in Delphi code?

    This is for sure worth doing. But is that what you mean when you talk about a 10% improvement above? Or are you measuring 10% in just a single function? And sorry to hark back to it, but in your StringReplace topic recently you were concentrating on utterly the wrong thing. There was a massive opportunity to optimise that code, and you have chosen not to take it. For reasons that escape me.
  14. 10.4.2 is near the end of beta. Maybe wait a little bit unless you take the update subscription (You should).
  15. balabuev

    10.4.1 Released today

    I've created hacker style fix for the TSpeedButton font issue SpeedButtonFontFix.pas (No need to change or replace any of standard source files. Just add the unit to your project and run) Same fix as design-time package. Fixes the font at design-time: pSpeedButtonFontFix.zip (open in IDE, right click the project file, choose "install" from context menu)
  16. Roger Cigol

    Create a Delphi Dll and load it with DllMain

    I'm not entirely sure that this thread of postings should be here under "C++ Builder"......
  17. Fr0sT.Brutal

    Quickly zero all local variables?

    An intrinsic that would be called only when told so? Sounds useful.
  18. Darian Miller

    How do you identify bottleneck in Delphi code?

    Are you using a Profiler to measure performance of your application, or simply timing specific code snippets? I'd suggest a Profiler if you aren't using one now...you'll tyipcally see the big bottlenecks pretty easily.
  19. Just press ctrl+shift+v instead of ctrl+v.
  20. Similarly, should work with records: type TMy = class private FPoint: TPoint; public property X: Integer read FPoint.X write FPoint.X; property Y: Integer read FPoint.Y write FPoint.Y; end; This can even be mixed with static arrays: type TMyData = record Points: array[0..1] of TPoint; end; TMy = class private FData: TMyData; public property X: Integer read FData.Points[1].X write FData.Points[1].X; property Y: Integer read FData.Points[1].Y write FData.Points[1].Y; end;
  21. David Heffernan

    Undocumented language enhancements

    The entire language is essentially undocumented. There is no formal specification, no documented grammar etc.
  22. TurboMagic

    DEC 6.1 released

    Hello, there is a new release 6.1 of DEC available . It is located here: https://github.com/MHumm/DelphiEncryptionCompendium/releases/tag/V6.1 WHat's new since V6.0? * x64 compilation works out of the box now, some unit had not been properly listed for x64 * fixed the following cipher algorithms which were broken on x64: Blowfish, RC6 and Q128 * the Sapphire cipher did work with the unit test vectors but failed for some others * added SHA2-224 hash algorithm * added HMAC and pbkdf2 algorithms * somebody provided a build batch file * there is a command line application included now for setting the IDE's library path * progress even got changed and a VCL demo for that one was added * version history is a separate document in docs folder now Cheers TurboMagic
  23. @David Heffernan I admire your patience.
  24. Stuart Clennett

    Handling MultipartFormData

    @alejandro The demo does not save the file at all. You are required to implement that. However it is quite simple. For example, in the `StoreDataAndFile` method in `Server.Resources.pas` you could use a memory stream to access the Bytes and save to a file if SameText(LParam.FieldName, 'image') and LParam.IsFile then begin Result.FileSize := Length(LParam.AsFile.Bytes); Result.FileName := LParam.AsFile.FileName; // This will save the file lStream := TMemoryStream.Create; try lStream.Write(LParam.AsFile.Bytes, Length(LParam.AsFile.Bytes)); lStream.SaveToFile(TPath.Combine(C_RootPath, TPath.GetFileName(LParam.AsFile.FileName))); finally lStream.free; end; end In this instance, `C_RootPath` is just a folder on the server where uploaded files should be saved, but you could make this dynamic based on user info in the Token for example. Hope this helps
  25. Implementing a fast hash table has way more and more important implications than picking the proper size and grow factor. Oh and proving that something is faster than another thing is far from trivial (as with most benchmarks). Interesting read: https://probablydance.com/2017/02/26/i-wrote-the-fastest-hashtable/
×