-
Content Count
1497 -
Joined
-
Last visited
-
Days Won
152
Everything posted by Stefan Glienke
-
My TStringList custom SORTing, trying to mimic Windows Explorer way
Stefan Glienke replied to programmerdelphi2k's topic in Algorithms, Data Structures and Class Design
Every time I see allocations for comparing strings I have to cry- 5 replies
-
- tstinglist
- sort
-
(and 2 more)
Tagged with:
-
combining two characters to a string switches them
Stefan Glienke replied to dummzeuch's topic in RTL and Delphi Object Pascal
Of course, the result will be as expected if you name the two functions differently, then it does not matter what order they are getting called - but when it's twice the same function which returns different results then the call order matters Here is the code to simulate the issue: var callNo: Integer; const PGM_Magic_Number = 'P5'; function ReadChar: Char; begin Inc(callNo); Result := PGM_Magic_Number[callNo]; end; procedure Test; var s: string; begin s := ReadChar + ReadChar; Writeln(s); end; begin Test; end; -
ReleaseExceptionObject not working?
Stefan Glienke replied to A.M. Hoornweg's topic in RTL and Delphi Object Pascal
We recently discussed this in https://quality.embarcadero.com/browse/RSP-18259 - even after reading the comment in System.pas I cannot imagine what the idea behind ReleaseExceptionObject was given that AcquireExceptionObject returns a reference and thus also passes ownership to the caller. Thus the parameterless ReleaseExceptionObject cannot work by design given that it does not have any parameter where you might pass the previous result of AcquireExceptionObject. Even the documentation tells that this routine is just there for backwards compatibility and should not be used (I would have marked it as deprecated long ago so people that might still have it in their code would remove it) https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.ReleaseExceptionObject -
How to modify the code for $R+
Stefan Glienke replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
This would not be of much use given that one can use include files or other means to control their compiler options. You want a way to preserve the effective options at a given location to restore precisely that state. -
Localization of constant arrays - best practice?
Stefan Glienke replied to Fr0sT.Brutal's topic in General Help
That "works" (i.e. you wont get a GPF) because typed consts are no real consts but rather read-only variables (as in you cannot directly assign to them regularly). But I am sure this will cause a memory leak - a static one but ReportMemoryLeaksOnShutdown should complain about it. -
How to modify the code for $R+
Stefan Glienke replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
Actually, it's way simpler: function BuildDigits(_Digits: UInt16; _Invalids: UInt8): UInt16; begin _Digits := UInt16((_Digits - 2048) * 11); _Digits := (_Digits and $FFFC) or (_Invalids and $03); Result := Swap(_Digits); end; IIRC a smaller than register size unsigned ordinal type will not cause an overflow when it wraps around 0 so it's not necessary to turn it into a signed to avoid that. The CPU uses 32bit register math anyway. The UInt16 of the multiplication is necessary though. -
How to modify the code for $R+
Stefan Glienke replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
Which you obviously didn't which is the raison d'être of this thread -
How to modify the code for $R+
Stefan Glienke replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
And my point was that you cannot assign signed to unsigned and vice versa without potentially getting them. -
How to modify the code for $R+
Stefan Glienke replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
Pretty much because the very first line already is subject to a range check error. Many people have not noticed many potential range check errors because range and overflow checks were disabled even in debug config and only after they finally changed that they occur in a lot of code that unknowingly implicitly converts between signed and unsigned. -
How to modify the code for $R+
Stefan Glienke replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
And why exactly would it be a problem to subtract 2048 from 0 in a signed 16-bit integer? -
Localization of constant arrays - best practice?
Stefan Glienke replied to Fr0sT.Brutal's topic in General Help
If you don't need language swapping while the application is running then go with the const array using resourcestrings. I say so because the const array is initialized on startup with the localized values from the resourcestrings. If you change language later they will not change. -
How to modify the code for $R+
Stefan Glienke replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
{$IFOPT R+}{$DEFINE RANGECHECKS_ON}{$R-}{$ENDIF} TempInt := TempInt * 11; {$IFDEF RANGECHECKS_ON}{$UNDEF RANGECHECKS_ON}{$R+}{$ENDIF} -
How to set event handler for generic TControl descendant using RTTI
Stefan Glienke replied to CoMPi74's topic in General Help
https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Procedural_Types_(Delphi)#Method_Pointers -
How to set event handler for generic TControl descendant using RTTI
Stefan Glienke replied to CoMPi74's topic in General Help
Event types and TMethod while binary compatible (both consist of the data and code pointer) they are not assignment compatible. This routine will work for all event handlers that have the TNotifyEvent signature but not for others (such as mouse or key-related ones that have additional parameters). For those, you need to write overloads. procedure SetDefaultEventHandlerIfEventExists2(const AControl: TControl; const AEvent: string; const AHandler: TNotifyEvent); begin if IsPublishedProp(AControl, AEvent) then SetMethodProp(AControl, AEvent, TMethod(AHandler)); end; -
FIY: Sort algorithms found by Deep learning
Stefan Glienke replied to Tommi Prami's topic in Algorithms, Data Structures and Class Design
I read "branchless" and I cry - see RSP-21955 -
Turn the strings into an enum or an index and put the functions into a const array over that enum/index.
-
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
Could the documentation be of any help? -
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
No, it's not - it's the call from this line: https://github.com/microsoft/microsoft-pdb/blob/master/PDB/msf/msf.cpp#L1627 It however might look different today given that source on GitHub is from seven years ago but it might still give a clue. The weirdest way I got a "thank you" ever ngl -
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
FWIW: https://github.com/microsoft/microsoft-pdb/blob/master/PDB/msf/msf.cpp#L1385 -
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
@Anders Melander Might be worth looking into https://github.com/llvm/llvm-project/blob/main/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp -
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
This could be some relevant info: https://randomascii.wordpress.com/2023/03/08/when-debug-symbols-get-large/ -
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
Yes - because apparently according to the warning, there is a problem with "match the module with the symbol file". It could be very well a VTune bug though - after all the 2023.1.0 we currently get is a "pre-release". -
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
I can't - as I confirmed the breaking change is from 2023.0.0 to 2023.1.0 and that explicit mention of large pdb file support was the most obvious clue. I don't know anything about the pdb format. -
MAP2PDB - Profiling with VTune
Stefan Glienke replied to Anders Melander's topic in Delphi Third-Party
I just upgraded from 2023.0.0 where it worked to 2023.1.0 where it does not. What I noticed in the change log of VTune 2023.1.0 is this: Debug Support Support for Large PDB Files Starting with the 2023.1 version, on Windows* systems, you can resolve debug information from PDB files larger than 4GB. Could it be that the address bitness written by map2pdb is not correct now? In the collection log of VTune I can see this warning: Cannot locate debugging information for file `somepath\Tests.exe'. Cannot match the module with the symbol file `somepath\Tests.pdb'. Make sure to specify the correct path to the symbol file in the Binary/Symbol Search list of directories. -
Personally, I would find it way more readable if you would not ifdef DELPHIAVX for every single line but simply make it two blocks, one using the avx instructions and one using db.