

DelphiUdIT
Members-
Content Count
789 -
Joined
-
Last visited
-
Days Won
18
DelphiUdIT last won the day on July 22
DelphiUdIT had the most liked content!
Community Reputation
253 ExcellentTechnical Information
-
Delphi-Version
Delphi 12 Athens
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Efficiency Mode for own app (FMX, Delphi12, Win11)
DelphiUdIT replied to Pamen's topic in Windows API
Why ? https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setprocessinformation https://learn.microsoft.com/en-us/answers/questions/4052040/efficiency-mode-causing-performance-issue This come from FireFox, and it's the UNIQUE in my 260 processes and 5000 Thread that go in a efficiency mode alone .... No other process known go in that mode, except if you force it with Task Manager. It is at "firefox-release\hal\windows\WindowsProcessPriority.cpp", you can translate in Delphi. -
Efficiency Mode for own app (FMX, Delphi12, Win11)
DelphiUdIT replied to Pamen's topic in Windows API
You can try this, derivated from Learn Microsoft - EcoQS and updated for Delphi (sorry for errors): //I use _my to discriminate from bundle definitions uses WinApi.Windows; //Add this to uses unit type ///<summary>Documentation: https://docs.microsoft.com/windows/win32/api/processthreadsapi/ne-processthreadsapi-process_information_class</summary> PROCESS_INFORMATION_CLASS_my = ( ProcessMemoryPriority, ProcessMemoryExhaustionInfo, ProcessAppMemoryInfo, ProcessInPrivateInfo, ProcessPowerThrottling, ProcessReservedValue1, ProcessTelemetryCoverageInfo, ProcessProtectionLevelInfo, ProcessLeapSecondInfo, ProcessMachineTypeInfo, ProcessInformationClassMax ); type _PROCESS_POWER_THROTTLING_STATE = record Version: ULONG; ControlMask: ULONG; StateMask: ULONG; end; PROCESS_POWER_THROTTLING_STATE = _PROCESS_POWER_THROTTLING_STATE; PPROCESS_POWER_THROTTLING_STATE = ^PROCESS_POWER_THROTTLING_STATE; const PROCESS_POWER_THROTTLING_CURRENT_VERSION = 1; PROCESS_POWER_THROTTLING_EXECUTION_SPEED = $1; //Redefine API function SetProcessInformation_my(hProcess: THandle; ProcessInformationClass: PROCESS_INFORMATION_CLASS_my; ProcessInformation: Pointer; ProcessInformationSize: DWORD): ByteBool; stdcall; function SetProcessInformation_my; external kernel32 name 'SetProcessInformation' delayed; implementation {$R *.fmx} function SetEfficiencyMode(PID: DWORD): Boolean; var hProcess: THandle; PowerState: PROCESS_POWER_THROTTLING_STATE; begin Result := false; hProcess := OpenProcess(PROCESS_SET_INFORMATION, False, PID); if hProcess <> 0 then begin ZeroMemory(@PowerState, SizeOf(PowerState)); PowerState.Version := PROCESS_POWER_THROTTLING_CURRENT_VERSION; PowerState.ControlMask := PROCESS_POWER_THROTTLING_EXECUTION_SPEED; PowerState.StateMask := PROCESS_POWER_THROTTLING_EXECUTION_SPEED; Result := SetProcessInformation_my(hProcess, Process_Information_Class_my(ProcessPowerThrottling), @PowerState, SizeOf(PowerState)); CloseHandle(hProcess); end; end; procedure TForm1.Button1Click(Sender: TObject); var Success: boolean; begin Success := SetEfficiencyMode(GetCurrentProcessId); if Success then ShowMessage('Efficiency mode activated successfully!') else ShowMessage('Error activating efficiency mode.'); end; -
Efficiency Mode for own app (FMX, Delphi12, Win11)
DelphiUdIT replied to Pamen's topic in Windows API
You can use WINMD or better this https://www.winsoft.sk/win32api.htm to get the update informations that you need. (EDIT: the link is taken from some topic of this forum) By now, I know little bit, seems that Microsoft is still working on this and the things will change (like an extensions of API function). For example the new definition of PROCESS_INFORMATION_CLASS is: PROCESS_INFORMATION_CLASS = ( ProcessMemoryPriority, ProcessMemoryExhaustionInfo, ProcessAppMemoryInfo, ProcessInPrivateInfo, ProcessPowerThrottling, ProcessReservedValue1, ProcessTelemetryCoverageInfo, ProcessProtectionLevelInfo, ProcessLeapSecondInfo, ProcessMachineTypeInfo, ProcessInformationClassMax ); A little bit different from old one. -
Try this. The DLL is present, but you can build the project, and then simply run directly from terminal line this (you must be in the path where the DLL is present): RUNDLL32 d.dll,Start Pay attention that you MUST CHANGE THE PATH AND THE FILENAME LINKED IN THE SOURCE, if you want that the link open the right file. NOTE: In the other console windows that should open, is going to be printed the path of the LNK file. Fucking DLL RUNDLL32.zip
-
Hello, first of all is better that you tell us what do you expectt from the runing DLL (e.g. found a LNK file in .....). I think there is some issues about your knowledge (I talk about Windows 11). If you run from a cmd prompt a RUNDLL32, the HOMEPATH you refer is "C:\Users\YOUR ACCOUNT NAME\AppData\Roaming" So, here is where the LNK file is created. And it is always created. About the pointed link file (JPG): this file, without none path should be under UNKNOWN PATH. So the file will never be linked. If you comile and run like an EXE instead, the path where the JPG file is "linked" is in the same directory as exe is. The DLL works perfect as expected. Notes: 1) Like I wrote before, you should PUT the "Timer1.Enabled := False;" at the begining of the event procedure. 2) Is missing the "CoInitializeEx(nil, COINIT_MULTITHREADED);": without that the CreateComObject will fail.
-
Calling routines overhead
DelphiUdIT replied to PeaShooter_OMO's topic in RTL and Delphi Object Pascal
Unless the application is critical to runtimes, the best approach is to focus on timing, code readability, and flexibility. Specifically, break long code into shorter chunks, passing few parameters so as to use only the CPU registers. Use the INLINE directive so that the code can be compiled by "including" it directly in the caller (in this case, the resulting executable will be larger but faster). You can also write parts in assembler to further optimize speed. Be aware, however, that this requires a thorough understanding of the topic and, above all, always provide a Pascal alternative in case the assembler isn't suitable for the processor used at runtime (e.g., Intel vs. ARM) or the platform. -
Calling routines overhead
DelphiUdIT replied to PeaShooter_OMO's topic in RTL and Delphi Object Pascal
The "if" is neutral, since it is alwys execute (may be a very little jmp that are assorbed by cache) ... you can try to invert the two calls and you will (should) see how is the timing. The different times are justified by the overhead (like @PeaShooter_OMO sayd) of the call (load the registers / stack, jmp, load the result / stack, return). It's right to define them INLINE, in this case you have a better timing (you can declare inline one, the other or all two to see the various timing). -
This are the project. Fucking DLL RUNDLL32.zip
-
I wrote that, HINSTANCE is a global var. HINST is the type.
-
HInstance is the instance (var) of the module, derived from System.pas (type HINST). Should be always defined and available 'cause it is used at loading time (look SysInit.pas) FYI, MainInstance in the HInstance of the MAIN APPLICATION (not the module like dll, library, ...).
-
Ah ah ah, are you sure that are really "private" ? One of the last Ollama model ("gemma3:12b" or "qwen3:30b-a3b" if I'm not wrong) can access Internet, of course you must excplicity ask for this, but it can.
-
Possible error in generated Units in "Windows API from WinMD"
DelphiUdIT replied to Memnarch's topic in Delphi IDE and APIs
There were other discussion about WINMD, that seems to be buggy, look there: https://en.delphipraxis.net/topic/13720-bugs-on-winmd-who-can-clarify/?do=findComment&comment=105350 In one post, @pcoder suggest the see others metadata provider (like this https://www.winsoft.sk/win32api.htm ). If you look insede of those sources, you will look that more types were derivered form SYSTEM unit, like IUNKNOWN for example. Try this instead WINMD. There are in QP some open issues about WINMD. -
Interesting read about Sleep(0/1) and SwitshToThread
DelphiUdIT replied to Tommi Prami's topic in Windows API
I think all is linked to the time of SO post, 15 years ago. Talking about CPU here is about CORE, when there are multiple CPU other things come in play and the sleep is the last of the issues. Take care now ( @Kas Ob. told this) that the real life is different: no one use affinity with one thread (yes, I do it but for really unique needs), the threads work are balanced by ITD (Intel Thread Director) that acts between OS and hardware, and also Windows may have changed some logics. If you look at your thread (not the one in the example that's "blocked" by Affinity), you'll see that it's "moved" by core during its lifetime. That is, a thread doesn't necessarily always run in the same core. So, if Microsoft were to say that SwitchToThread works in a certain way with modern hardware... well, I wouldn't be so sure, or rather, not in the context we're imagining, given that the load distribution is dynamic. -
What you indicated is not the last one: (of course you could have installed it manually too...). But, if you don't find the source files, obviously something went wrong during the installation. Did you check the installation for all platforms during the installation of Rad Studio? (I did)