-
Content Count
3417 -
Joined
-
Last visited
-
Days Won
113
Everything posted by Lars Fosdal
-
Anyways - under Windows, we have the so-called multimedia timer, https://docs.microsoft.com/en-us/windows/win32/multimedia/about-multimedia-timers but a caveat is that actual minimum resolution varies with platform and device https://docs.microsoft.com/en-us/windows/win32/multimedia/timer-resolution var TCaps: TTimeCaps; // WinAPI.MMSystem; rc: MMResult; begin rc := timeGetDevCaps(@TCaps, SizeOf(TCaps)); // WinAPI.MMSystem; if rc = 0 then Writeln(Format('Min %d / Max %d', [TCaps.wPeriodMin, TCaps.wPeriodMax])) else Writeln(Format('timeGetDevCaps returned %d', [rc])); end; outputs Min 1 / Max 1000000 on my computer. Oddly enough, the resolution is 1ms - so, in theory it is impossible to use a timer to get a better resolution than 1 ms. Still - the WaitableTimer has 100ns resolution, so that should work, right? https://docs.microsoft.com/en-gb/windows/win32/api/synchapi/nf-synchapi-setwaitabletimer function NanoSleep(const NanoSec: Int64):Boolean; var Timer: THandle; Constraint: _Large_Integer; begin Result := False; Timer := CreateWaitableTimer(nil, True, nil); if timer <> 0 then try Constraint.QuadPart := -NanoSec; if SetWaitableTimer(Timer, Constraint.QuadPart, 0, nil, nil, False) then begin WaitForSingleObject(Timer, INFINITE); Result := True; end; finally CloseHandle(Timer); end; end; but even that is incredibly erratic. const ns: Int64 = 10000; var st: TStopWatch; ix: Integer; begin st := TStopWatch.StartNew; for ix := 1 to 10 do NanoSleep(ns); st.Stop; Writeln(st.ElapsedMilliseconds); end; and does not seem to work at low intervals - unless I screwed something up? Windows is not a real time OS - so it seems milliscond timing will be iffy - unless you use a power consuming loop of instructions - and that is not desirable.
-
I am curious - when would you need such minuscule intervals?
-
custom attributes question
Lars Fosdal replied to David Schwartz's topic in RTL and Delphi Object Pascal
TRttiType.GetProperties.GetAttributes vs TRttiType.GetFields.GetAttributes Personally, I've avoided setting props on fields and only set them on properties. There are parts of the RTL where the opposite applies - f.x. for REST.JsonReflect, which checks the fields and not the properties. -
class designation question
Lars Fosdal replied to David Schwartz's topic in Algorithms, Data Structures and Class Design
Guilty. Like OOP, Generics are sooo addictive! -
My first thought was - why not use a thread with sleep if you need that fast a timer - but - again, multithreading raises its own issues.
-
Dictionaries, Hashing and Performance
Lars Fosdal replied to Clément's topic in Algorithms, Data Structures and Class Design
What about the theory that dictionaries have fewer collisions if you set the capacity to be a prime number ? Fact or fiction? Personally, I do actually set the capacity to a prime, but I am not quite sure if it because it is sound advice or if it is a cargo cult thing. Edit: Funny enough, @Tommi Prami posted an alternative approach.- 53 replies
-
- tdictionary
- tstringlist
-
(and 2 more)
Tagged with:
-
As a Delphi expert, do you ever need to refactor or improve your code?
Lars Fosdal replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Less readable code can be greatly alleviated with decent commentary. Document general intent and method rather than say what each line does. -
As a Delphi expert, do you ever need to refactor or improve your code?
Lars Fosdal replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Empirically proven to work. "Awful" can be - slow code, albeit in a context where performance is not required - cryptic code - code that could be simplified with modern RTL code Anyways - Refactor when you need to, and not just because you'd like to - unless unlike most devs, you have time to spare. Oh - as @Stefan Glienkesuggests: Make sure you have the tests to validate your refactoring. -
As a Delphi expert, do you ever need to refactor or improve your code?
Lars Fosdal replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
Another challenge is knowing when NOT to refactor. "This code works, but it looks awful... should I refactor?" -
Any Good tutorial on Parallel Programming Library?
Lars Fosdal replied to Tommi Prami's topic in RTL and Delphi Object Pascal
Since threading is non-trivial, it is hard to make examples that are not either non-trivial or oversimplified. You may find yourself writing quite a bit of scaffolding code, which would have come for free with OTL. -
Any Good tutorial on Parallel Programming Library?
Lars Fosdal replied to Tommi Prami's topic in RTL and Delphi Object Pascal
What are your needs / goals? -
Running commandline app and capturing output
Lars Fosdal replied to Tommi Prami's topic in Windows API
Is the behavior erratic across multiple executions of the same application - or is it specific applications that do not let you capture? -
True, but the point is a more natural limit of variable scope. var ref := Some.Array[Index1].Reference; var thing := Function(Index1).Thing; if ref.Value <> thing.Value then begin ... end; // ref and thing ARE present here I guess you could wrap it in another pair of begin/end - but that would look a bit strange, while the with signals clearly that these are local.
-
I'd like this to be possible, and a compiler switch that bans the old with statements. with var ref := Some.Array[Index1].Reference, var thing := Function(Index1).Thing do begin if ref.Value <> thing.Value then begin ... end; end; // ref and thing are not present
-
Did you mean https://quality.embarcadero.com/browse/RSP-18953 - Tommi? 21814 is the Windows 10 Ansi/UTF-8 QP - which, by the way, returns different values on my Windows 10 Enterprise 1809 10.0.17763.831, depending on which PowerShell version you use. PowerShell 5.1 IsSingleByte : True BodyName : iso-8859-1 EncodingName : Western European (Windows) HeaderName : Windows-1252 WebName : Windows-1252 WindowsCodePage : 1252 IsBrowserDisplay : True IsBrowserSave : True IsMailNewsDisplay : True IsMailNewsSave : True EncoderFallback : System.Text.InternalEncoderBestFitFallback DecoderFallback : System.Text.InternalDecoderBestFitFallback IsReadOnly : True CodePage : 1252 PowerShell 6.2.4 Preamble : BodyName : utf-8 EncodingName : Unicode (UTF-8) HeaderName : utf-8 WebName : utf-8 WindowsCodePage : 1200 IsBrowserDisplay : True IsBrowserSave : True IsMailNewsDisplay : True IsMailNewsSave : True IsSingleByte : False EncoderFallback : System.Text.EncoderReplacementFallback DecoderFallback : System.Text.DecoderReplacementFallback IsReadOnly : True CodePage : 65001
-
Anyone compiled Android apps (api 16) for Industrial devices with Android 4.1.x
Lars Fosdal replied to microtronx's topic in Cross-platform
What are the odds that FMX in Rio uses something that is not present in SdkVersion 14? -
How to make app with tabbed set of VNC windows
Lars Fosdal replied to David Schwartz's topic in General Help
In that case, Remote Desktop Manager is the way to go. -
Would it be possible to wrap the assembly versions of these in Delphi? https://www.nayuki.io/page/fast-sha2-hashes-in-x86-assembly
-
How to make app with tabbed set of VNC windows
Lars Fosdal replied to David Schwartz's topic in General Help
If the need is simply parallel remote control like starting/stopping scripts/apps or services - you would do much better by using PowerShell. -
How to make app with tabbed set of VNC windows
Lars Fosdal replied to David Schwartz's topic in General Help
@David Schwartz Have you guys tried https://remotedesktopmanager.com/ ? It is freaking awesome for managing a large server park! We have literally hundreds of servers and would be lost without it. It supports pretty much every remoting protocol you can think of: https://remotedesktopmanager.com/features/remote-connection-management You can have the windows tabbed, cascaded, tiled vertically or horizontally. You can lock the Windows hotkeys so that you have to use the mouse to get out of the context of the remote view. I.e. Alt-Tab happens within the focused remote connection. There is a free version for personal use, but if you have a team, you want the enterprise version. -
Custom TrueType font in FMX Android app?
Lars Fosdal replied to Lars Fosdal's topic in Cross-platform
Do all of them involve creating a modified FMX.FontGlyphs.Android.pas !? Is there a QP I can vote for to improve this somehow? -
Overloaded generic methods
Lars Fosdal replied to chkaufmann's topic in RTL and Delphi Object Pascal
Must it be an overload? Why not FindComponentsByClass vs FindComponentsWithInterface ? -
Detect user location from ip address
Lars Fosdal replied to Mark Williams's topic in Network, Cloud and Web
It is a joke - implying that if you surf from the space station, you get dating ads that are "near you" as spammers often use geolocation to generate fake ads for offers in your area. -
Detect user location from ip address
Lars Fosdal replied to Mark Williams's topic in Network, Cloud and Web
Geolocation from IP address: https://www.iplocation.net/ip-address -
What are your compiler settings for debug builds?
Lars Fosdal replied to dummzeuch's topic in Delphi IDE and APIs
Same as @dummzeuch We also leave range checks on for release versions. For us, API and database access times dwarf the array access times, and there is nothing quite like live data to throw curveballs at your algorithms.