delphi零碎笔记01

【delphi11】delphi进阶【七、多线程编程在Delphi中的实现】 在深入Delphi的多线程编程之前,首先要理解并发(Concurrency)和多线程(Multithreading)的概念。:并发是指系统能够处理多个任务的能力,这些任务可能会交错执行,但在任意时刻,可能只有一个任务在执行。:多线程是并发的一种形式,它允许在同一个程序中同时运行多个线程来执行不同的任务。 阅读详情

delphi零碎笔记01

001、uses System.SyncObjs; //同步对象

  TEvent = class(THandleObject)

002、uses System.Threading;

//线程、线程池、线程池中线程的安全共享标记、线程池的状态、

//任务、池化的任务

  [HPPGEN(HPPGenAttribute.mkFriend, 'DELPHICLASS TTask; /* __interface */ ITask; DELPHICLASS TAbstractTask')]
  TThreadPool = class sealed
  public type
    IControlFlag = interface(IInterface)
      function Increment: Integer;
    end;

      //...::::::线程池

      TSafeSharedCardinal = record
      //...线程池中线程的安全共享标记
      public
        constructor Create(var SharedVar: Cardinal);
        function Increment: Cardinal; inline;
        function Decrement: Cardinal; inline;
        class operator Explicit(Value: TSafeSharedCardinal): Cardinal; inline;

        property Value: Cardinal read GetCardinal write SetCardinal;
      end;

  public //线程池公共属性、方法、函数::::::
    constructor Create;
    destructor Destroy; override;

    class function NewControlFlag: IControlFlag; static;

    procedure QueueWorkItem(Sender: TObject; WorkerEvent: TNotifyEvent; const AControlFlag: IControlFlag = nil); overload;
    procedure QueueWorkItem(const WorkerEvent: TProc; const AControlFlag: IControlFlag = nil); overload;

    // Returns false if attempting to set a value smaller than the number of processors. Setting this
    // value too high can lead problems with other libraries and processes. If too many threads execute
    // at the same time, task/thread switching overhead can become restrictive.
    function SetMaxWorkerThreads(Value: Integer): Boolean;
    // Returns false if attempting to set a value < 0 or > MaxWorkerThreads. The actual number of pool
    // threads could be less than this value depending on actual demand. Setting this to too few threads could
    // be less than optimal resource utilization.
    function SetMinWorkerThreads(Value: Integer): Boolean;

    property MaxWorkerThreads: Integer read GetMaxWorkerThreads;
    property MinWorkerThreads: Integer read GetMinWorkerThreads;

    ///  <summary>
    ///  The default global threadpool.
    ///  </summary>
    class property Default: TThreadPool read FDefaultPool;
    ///  <summary>
    ///  This will be the threadpool when accessed from a thread within that threadpool. For the main-thread or
    ///  non-threadpool threads, this will be the same as the Default property above.
    ///  </summary>
    class property Current: TThreadPool read GetCurrentThreadPool;
  end;

  TThreadPoolStats = record

  //...线程池的状态::

  public
    ///  <summary>Total number of worker threads within the thread pool</summary>
    property WorkerThreadCount: Integer read FWorkerThreadCount;
    ///  <summary>Corresponds to the MinWorkerThreads property</summary>
    property MinLimitWorkerThreadCount: Integer read FMinLimitWorkerThreadCount;
    ///  <summary>Corresponds to the MaxWorkerThreads property</summary>
    property MaxLimitWorkerThreadCount: Integer read FMaxLimitWorkerThreadCount;
    ///  <summary>Number of threads waiting for work to do</summary>
    property IdleWorkerThreadCount: Integer read FIdleWorkerThreadCount;
    ///  <summary>Number of global queued work requests</summary>
    property QueuedRequestCount: Integer read FQueuedRequestCount;
    ///  <summary>Number of worker threads in the process of being retired</summary>
    property RetiredWorkerThreadCount: Integer read FRetiredWorkerThreadCount;
    ///  <summary>Running average of CPU usage</summary>
    property AverageCPUUsage: Integer read FAverageCPUUsage;
    ///  <summary>Current snapshot of CPU usage</summary>
    property CurrentCPUUsage: Integer read FCurrentCPUUsage;
    ///  <summary>Shared value among worker threads to manage orderly thread suspension</summary>
    property ThreadSuspended: Integer read FThreadSuspended;
    ///  <summary>Shared value among worker threads to manage orderly thread suspension</summary>
    property LastSuspendTick: Cardinal read FLastSuspendTick;
    ///  <summary>Used by the monitor thread to keep from creating threads too quickly</summary>
    property LastThreadCreationTick: Cardinal read FLastThreadCreationTick;
    ///  <summary>Used by the monitor thread to only create new threads when there is work to do</summary>
    property LastQueuedRequestCount: Integer read FLastQueuedRequestCount;

    ///  <summary>
    ///  When called from within a threadpool thread, returns the stats for the owning threadpool. Outside of a
    ///  threadpool thread, this will return the stats for the default threadpool
    ///  </summary>
    class property Current: TThreadPoolStats read GetCurrentThreadPoolStats;
    ///  <summary>Returns the stats for the default threadpool</summary>
    class property Default: TThreadPoolStats read GetDefaultThreadPoolStats;
  end;    //::线程池的状态

 

010、Timeout: TTimeSpan //时间截的最完整的record记录类型:内含时间记号(滴答)Tick:

  public const
    TicksPerMillisecond = 10000;
    TicksPerSecond = 1000 * Int64(TicksPerMillisecond);
    TicksPerMinute = 60 * Int64(TicksPerSecond);
    TicksPerHour = 60 * Int64(TicksPerMinute);
    TicksPerDay = 24 * TIcksPerHour;

//及很丰富的属性、函数和过程

011、Timeout: Cardinal = INFINITE //const  INFINITE = Cardinal($FFFFFFFF); //无符号最大整数:应用:一直等下去://ITask.wait(INFINITE);

012、TThread.GetTickCount

class function TThread.GetTickCount: Cardinal;
{$IF Defined(MSWINDOWS)}
begin
  Result := Winapi.Windows.GetTickCount;
end;
{$ELSEIF Defined(MACOS)}
begin
  Result := AbsoluteToNanoseconds(mach_absolute_time) div 1000000;
end;
{$ELSEIF Defined(POSIX)}
var
  res: timespec;
begin
  clock_gettime(CLOCK_MONOTONIC, @res);
  Result := (Int64(1000000000) * res.tv_sec + res.tv_nsec) div 1000000;
end;
{$ELSE OTHERPLATFORM}
  {$MESSAGE Fatal 'Method not implemented for Platform'}
{$ENDIF OTHERPLATFORM}

013、TMarshaller

type
  // High-level aid for marshalling arguments to and from OS / native API invocation.操作系统高级别助手:集结编组参数和OS /原生API的调用请求。
  // Auto-destruction to ease use.  轻松使用”自动解构“。

  TMarshaller = record

  //  .....

    // Complete all pending operations. This:
    // * un-fixes any fixed arrays or strings
    // * copies back any out or in/out paramaters
    // * frees any memory allocated for copied data
    // When the marshaller record goes out of scope, Flush is called automatically.

  / /完成所有的等待/期待的操作。它会:
  / / * un-fixes任何固定数组或字符串
  / / * 产生任何内存进出参数的副本
  / / * 释放分配的内存复制数据
  / / 当marshaller集结编组记录超出范围时,Flush自动清洗被自动调用:

    procedure Flush;  //:但会增加CPU或GPU的计时

// 用法:

var 
    LMarshaller:TMarshaller;

// ......

LMarshaller.Flush;  // :操作系统高级别:清理内存分配、回写任何进出参数、清零数组和strings //:但会增加CPU或GPU的计时

 

 

Delphi语言的多线程编程 多线程编程是指在一个程序中同时执行多个线程的技术。线程是程序执行的基本单位,它可以与其他线程并发执行,从而提高程序的性能。在多线程编程中,我们可以将一个大的任务分解成多个小任务,并行处理,从而缩短执行时间,提高响应速度。首先,我们需要创建一个自定义线程类,继承自TThread:```delphitypeprotectedoverride;end;begin// 这里放置线程要执行的代码begin// 模拟长时间的任务Sleep(100);end;end;``` 阅读详情

相关推荐

Delphi 多线程实例

Delphi 多线程实例 代码是个实例解压后即可运行,经过测试

Delphi 调用 DLL 里面的 C 函数传递字符串

Delphi 专家李维有篇文章,针对本文标题的情况,介绍了一种代码的写法。

pcplayer的博客 1562

System.SysUtils.TMarshaller 与 System.TMarshal.mht

System.SysUtils.TMarshaller 与 System.TMarshal.mht

System.SysUtils.TMarshaller 与 System.TMarshal

TMarshaller(结构) 基于 TMarshal(是有一大堆的 class 方法组成的类) 实现. TMarshaller 可以对缓存区进行自动(自动释放)安全地管理, TMarshal 也有前者没有的重要方法, 譬如: TMarshal.Copy() 方法. 有了它们, 以后关于内存缓冲区, 字符串转码等操作就更方便了. {测试} procedure TForm...

weixin_33913332的博客 132

从Unitree B2W到四足机器人:用Isaac Lab构建强化学习奖励函数的5个实战技巧

本文分享了在Isaac Lab仿真环境中,为Unitree B2W等四足机器人设计强化学习奖励函数的5个核心实战技巧。内容涵盖奖励函数的结构化组合、轮腿混合机器人的适配策略、课程学习的动态调整、域随机化增强鲁棒性以及高效的调试可视化方法,旨在帮助开发者构建更稳定、高效的机器人运动策略。

lg888的博客 1070

MCU 微控制器,在实际项目中如何选型(以 STM32为例)

1.MCU 选型需要考虑的一些因素 2.案例:传感器设备的 MCU 选型

创享 AIOT 的专栏 1万+

Delphi For Android 开发笔记 2 NEXTGEN下的字符串类型

delphi开发速度迅捷至少有30%(猜的,呵呵)的原因是因为其字符串(string、WideString、PChar、PAnsiChar等)处理能力。 而从delphi XE4开始,在system等单元中,出现了一个叫 NEXTGEN 的编译条件,这条件是在进行移动开发时自动定义的,而传统桌面开发时没有定义NEXTGEN。 这个编译条件直接导致原来的PAnsiChar、AnsiString无...

weixin_30469895的博客 488

Win10/Win11系统下,用VSCode编译Betaflight固件最全避坑指南(从GCC安装到HEX生成)

本文详细介绍了在Win10/Win11系统下使用VSCode编译Betaflight固件的完整流程,包括GCC安装、环境变量配置、终端选择、Make工具安装等关键步骤,帮助开发者避开常见陷阱,高效生成HEX文件。特别针对VSCode环境优化和编译错误排查提供了实用解决方案。

weixin_42557803的博客 422

Delphi跨平台下的GetTickCount,GetCurrentThreadID

在Windows下只要uses Windows,就有这两个API可调用GetTickCount,GetCurrentThreadID 如果我们需要跨平台使用这两个函数,就不能仅仅UsesWindows了。 如果需要跨平台使用GetTickCount,可以uses System.Classes,然后使用类方法:TThread.GetTickCount 如果需要跨平台使用GetCurrentT...

weixin_30340775的博客 384

FoundationPose复现及Realsense应用

FoundationPose是一个统一的基础模型,用于6D对象姿态估计和跟踪,支持基于模型和无模型的设置。在测试时可以立即应用于未见过的新对象,无需微调,只要给出其CAD模型,或者捕获少量RGBD参考图像。得益于统一框架,下游姿态估计模块在两种3D模型设置中都是相同的,当没有CAD模型时,使用神经隐式表示进行高效的新视角合成。通过大规模合成训练,辅以大型语言模型(LLM)、一种基于transformer的新架构和对比学习公式,实现了强大的泛化能力。

m0_56661101的博客 1万+

那些年对支付宝的研究[整理]

支付宝功能强大.他内部各个功能间的跳转是通过Uri 实现的.而使用window.location.href 即可.跟浏览器一样的协议.很方便 H5启动支付宝: alipays://platformapi/startapp?appId=20000067&url=网址 alipays://platformapi/startapp?appId=20000691&url=网址 ali...

技术专研 8923

Delphi中的匿名方法

在js的世界里,基本就是大量的“回调”和“异步”函数,剩下的就是按照顺序执行的javascript代码,所以总的来说,js中无“同步模型”。正是因为如此,javascript在运行时没有“多余的”线程,它们都在同一个“线程”中工作。任何第三方平台,凡是其API-Proxy代理服务器向你“代理转发(重定向)URL”,其响应结果,要么你在浏览器的导航器的地址栏中去取(Navigator.Location),要么你在响应头的redirect参数中去取,它们,都是异步的。Delphi及C++ Builder中,可以

pulledup的博客 1826

C# 上位机内存泄漏排查指南:3 个工具 + 4 个技巧,从 GC 频繁到稳定运行 720 小时

C# 上位机内存泄漏排查的核心是「先定位泄漏存在,再追溯引用根源,最后修复验证通过「Visual Studio 诊断工具(快速定位)+ dotMemory(深度分析)+ PerfView(生产监控)」三个工具的配合,结合「复现场景、排查静态成员+事件、检查非托管资源、GC 日志验证」四个技巧,可高效解决绝大多数泄漏问题。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 744

delphiXE IOS编程零碎1-沙盒(沙箱)

delphiXE IOS编程零碎1-沙盒(沙箱) 一、 uses iOSapi.Foundation, iOSapi.Helpers //2019-07-22临时添加:IOS运行时刻库等 , Macapi.Helpers ,iOSapi.UIKit , iOSapi.CoreGraphics, FMX.Helpers.iOS ; 二、 {$IFDEF IOS} funct...

pulledup的博客 1031

【Unity】【VR】如何让Distance Grab抓取物品时限制物品的Rotation

VR中Canvas抓取旋转问题的解决方案 在VR应用中,Canvas作为UI面板常需被抓取拖动,但默认会随手柄产生Z轴旋转,导致UI歪斜。Unity的Rigidbody冻结旋转功能对此无效,因为XR抓取直接修改Transform而非物理模拟。

每日出拳老爷子的博客 613

华为OD机试双机位C卷-简单的解压缩算法(C/C++/Py/Java/Js/Go)

华为OD机试(机考)双机位C卷 【简单的解压缩算法】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD真题【简单的解压缩算法】。

qq_45776114的博客 483

Delphi并行库System.Threading 之ITask 1

不知什么时候,也许是XE8,也许是XE8之前 .Delphi里面多了个System.Threading的并行库. 虽然己经有非常棒的第三方并行库QWorker,但我还是更喜欢官方的东西. 下面是一段使用System.Threading中ITask的代码 procedure TForm3.SpeedButton1Click(Sender: TObject); var tasks...

weixin_30549175的博客 825

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

聊聊线程池那些事

前言 平时开发过程中,我们会经常和线程池打交道,有时还会根据不同的业务进行线程池隔离,那么了解线程池的工作原理和参数设置就是非常必要的,所以今天的主题就是探究线程池的那些事儿。 为什么使用线程池 在使用一项技术之前,了解 「why」 是至关重要的,即我们为什么要使用线程池?线程池有什么好处? 线程池是一种池化技术,使用线程池可以减少线程创建时的资源消耗,同时也可以提高响应速度,即当有任务到达时,如...

pjmike的博客 389

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

JAVA多线程(八)——Callable,FutureTask以及CompletableFuture简介

个人学习笔记之——FutureCallaleFutureTask简介get方法awaitDone方法cancel方法run方法FutureTask使用样例CompletableFuture简介 Callale 对于Callable大家应该都很熟悉,它与Runnable属于线程的顶级接口,不过它与Runnale不同的是,它支持线程返回执行结果,下面是它的使用方法: package com.example.demo.thread; import java.util.concurrent.*; /** *

孙志南的博客 898

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Delphi 知识 并行编程 Tasks

在上面这种情况下,长的和假的操作是在匿名方法中执行的。当该函数结束时,其返回值被传递给另一个匿名方法,它是一个过程,并在UI线程中运行。嗯,在通常的情况下,你考虑一个任务,这并不意味着你将不再创建线程,但是,在许多情况下,你将使用排序的任务而非普通的线程。Delphi的PPL的使用相当简单,不需要对你的应用程序进行大的改动。适用于Delphi所支持的所有平台,并提供了一些先进的功能,如运行任务、连接任务、等待任务执行等。不是一个标准的Delphi异常块,它只是一个匿名方法,实际可以获得一个异常对象。

sensor_WU 博客 2452

Delphi D10.X 并行库PPL编程之TTask

delphi中的RTL(运行库)提供了并行编程库(PPL --Parallel Programming Library) ,让您的应用程序可以在跨平台应用中有效的使用多个CPU并行运行任务的能力。其次,我们再选中CheckBox1,按下启动按钮并开始,界面上进度条保持原运动状态,3秒后得到计算结果,计算的执行过程中没有影响到界面任务的执行。总之,TTask类是Delphi中强大的多线程编程工具,它允许您创建并发任务,以便同时执行多个操作,从而提高应用程序的性能和响应性。

GuoGuoABC 1620

Delphi线程内部

目录 Delphi线程内部 unit System.Classes; unit System; unit System.Threading; //Delphi的内部用户态线程库 如何池化线程并进行管理: 3.1、ITask--->TTask 未来:也是池化的任务接口 并行库,也是池化的: Delphi线程内部 unit System.Classes; function ThreadProc(const Thread: TThread): Intege...

pulledup的博客 2451

DELPHI XE7 新的并行库

DELPHI XE7 的新功能列表里面增加了并行库System.Threading, System.SyncObjs。 为什么要增加新的并行库? 还是为了跨平台。以前要并行编程只能从TThread类继承进行多线程处理,大家知道TThread类是从WINDOWS的线程API封装起来的,它封装的是WINDOWS的多线程的东西,是不能脱离WINDOWS的,当然是不能跨平台的。DELPHI现在走的是原...

weixin_30765505的博客 222

Delphi D10.X安卓开发中按两次返回键退出系统的方法

在安卓APP应用中,通常按下返回键后会关闭程序,有时候我们为了避免误按返回健导致程序的退出,会对按下返回健进行检测,并要求连续按下两次才退出程序。 在Delphi中开发安卓时,如何检测并实现两次退出APP呢。你可以使用发下方式。

tanqth的专栏 1万+

Delphi 的操作符重载 - Record 结构体

Delphi 的结构体类型的操作符重载,以及属性和事件。

pcplayer的博客 907
上一篇: ARC自动引用计数与方法function过程procedure的传参的对象类型及其回调值
下一篇: delphi function或procedure static;overload;override;abstract;virtual;dynamic;inline;stdcall;reintrodu
专讲冷知识
博客等级 码龄15年 568粉丝 292原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

专讲冷知识

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址