Inside CBase class - six essential questions

fdbus之同步调用invoke的实现分析 虽然是同步调用,但是在条件变量mWakeupSignal阻塞之前调用了send方法,通过send方法源码可以看到虽然是同步调用,但是还是将消息数据或者说消息对象压入到事件队列,然后通过事件循环依次进行处理,不同的是通过条件变量mWakeupSignal调用wait方法对调用线程进行了阻塞,然后等待接收回复消息,并唤醒调用线程。通过上面代码可以看到CFdbMessage下invoke的同步调用接口包含两个参数,一个是指向消息对象的共享指针,一个是超时时间。这些个方法都是由端点调用的,是用户调用的入口。 阅读详情

Everybody knows C-class in Symbian, the so called C-class is the one derived from class CBase. CBase is widely used in Symbian APIs, because it represents the class which should be created on heap. Every Symbian programmer knows how to call NewL() or NewLC() ( may be new (ELeave) ) of the CBase derived class to create the object, but not many people would really look into the CBase class itself to see why it has some interesting features.

If you can answer the following questions, you can skip this article, because you are a Symbian programmer with strong curiosity. If you are not sure about some answers, I recommend you to read this ariticle, because CBase class is essential in Symbian OS and it's interesting to know some features of this class. The questions are:

1. Why does cleanup stack has 3 versions of PushL() including PushL( CBase *aPtr )?
2. Why does CBase have a public virtual destructor?
3. How is CBase derived object initialized to binary zeroes?
4. Why is CBase derived object initialized to binary zeroes?
5. Why use new[] to initialize CBase derived object is not recommended?
6. Why does CBase has a private copy constructor and a private operator = function?

Let's get into these questions one by one.

Why does cleanup stack has 3 versions of PushL() including PushL(CBase *aPtr)?

It's an interesting question, there're 3 versions of PushL() in CleanupStack, they're PushL(TAny *aPtr), PushL(CBase *aPtr) and PushL(TCleanupItem anItem), why not just PushL(TAny *aPtr) and PushL(TCleanupItem anItem)? Let's see how cleanup stack works. Usually we use the code like this:

  1. CTest* test = CTest::NewL(); // CTest is a CBase derived class
  2. CleanupStack::PushL( test );
  3. test->FunL();
  4. CleanupStack::PopAndDestroy();

It's the regular use of cleanup stack, push the pointer "test" into the cleanup stack because FunL() may leave, after that, if everything is fine, pop the pointer and destory the object. Let's consider how does cleanup stack destory the object when calling PopAndDestroy(), according to the SDK helper, "If the item on the stack is a CBase* pointer, the pointer is removed from the stack and the object is destroyed with delete. If the item on the stack is a TAny* pointer, the pointer is removed from the stack and the memory occupied by the object is freed with User::Free()."

Why does cleanup stack has to judge if the pointer's type is CBase* or TAny*? Becasue a class may provide a private destructor! If a class has a private destructor, calling delete on this pointer will be invalid. In this case, system only calls User::Free() to free the memory of the object itself but can't invoke its destructor.

What happens to CBase derived class? If you take a look at e32base.h(the declaration of CBase is inside, actually part of the declaration), you will find CBase has a public virtual destructor. This ensures the cleanup stack can call delete on the CBase and its derived classes' pointers. It's useful to keep this in mind that if you push a non-CBase class pointer into the cleanup stack, the stack won't call your class's destructor. So, in most of the cases, you would like to either push CBase derived class into cleanup stack or never allocate heap memory in other types of classes.

But if you really want to allocate heap memory in other types of classes, the third version of PushL() can help you out. What you need to do is define a function which will do the cleanup and wrap the object by TCleanupItem.

Why does CBase have a public virtual destructor?

We can divide this question into 2 parts, why virtual, why public? The answer above tells you why public. The reason to make it virtual is simple. Sometimes you want to write the code like this:

  1. CBase* test = CTest::NewL(); // CTest is a CBase derived class
  2. CleanupStack::PushL( test );
  3. test->FunL();
  4. CleanupStack::PopAndDestroy();

With the virtual keyword, cleanup stack can make sure it will destroy the object properly by the base class's pointer.

How is CBase derived object initialized to binary zeroes?

Luckily, since all the new operator functions of CBase is inline, we can see the implementation of every function in e32base.inl. For example for "TAny* operator new(TUint aSize, TLeave)" the implementation is :

inline TAny* CBase::operator new(TUint aSize, TLeave)
 { return User::AllocZL(aSize); }

Here it uses User::AllocZL(), it allocates a cell of specified size from the current thread's default heap, clears it to binary zeroes, and leaves if there is insufficient memory in the heap. That's how CBase derived object is initialized to binary zeroes?

Why is CBase derived object initialized to binary zeroes?

Let's consider the code below :

  1. CTest* CTest::NewLC()
  2. {
  3.  CTest* self = new ( ELeave ) CTest;
  4.  CleanupStack::PushL( self );
  5.  self->ConstructL()
  6.  return self;
  7. }
  8. void CTest::ConstructL()
  9. {
  10.  iPointer = CMustLeave::NewL(); // assume this leaves
  11. }
  12. CTest::~CTest()
  13. {
  14.  if( iPointer )
  15.  {
  16.   delete iPointer;
  17.   iPointer = NULL;
  18.  }
  19. }

If CBase doesn't initialize the object to binary zero, and you don't initialize the iPointer to NULL manually, the initial value of iPointer is uncertain. Once CMustLeave::NewL() leaves, the value of iPointer is still uncertain(in most of the cases it's not zero). Since in NewLC, CTest was pushed into the cleanup stack, so system will pop the pointer and call CTest's destructor. This will cause the problem, because the if condition will be true and you will call delete on a pointer which doesn't pointer to a legal memory. Mostly program will crash. You will not meet this problem if iPointer was initialized to zero(NULL).

Why use new[] to initialize CBase derived object is not recommended?

There're a number of overloaded new operator functions in CBase class, but there's no new[] operator function. So if you use new[] to create CBase objects, you will not get the memory with binary zero. If you want to create a array of CBase derived class you can use the class like RPointerArray to deal with it.

Why does CBase has a private copy constructor and a private operator = function?

This is a general method to prevent the developer from the shallow copy accidently. If you write the code like this :

  1. CBase* pointer = new ( ELeave ) CBase;
  2. CBase base = *pointer;  // call copy constructor

The compiler will complain "illegal access from CBase to protected/private member CBase::CBase(const CBase&)", because the second line will try to call the copy constructor of CBase. If you write the code like :

  1. CBase* pointer = new ( ELeave ) CBase;
  2. CBase base;
  3. base = *pointer;  // call operator =

The compiler will also complain because it will call the operator = function. If you really want to do the deep copy you can write your own public copy constructor and operator = function. The reason that CBase do this is in most cases you will allocate some heap memory inside a CBase derived class, and it doesn't make sense(or I can say it's dangerous)to use the default copy constructor or default operator = function of this kind of class. So CBase turns this feature off by default.

Actually, in Symbian, to provide your own public version of copy contructor or operator = function is not a good idea neither. Because these 2 function are not leaving functions, but the code inside these 2 functions may leave sometimes( will call new (ELeave) or NewL() ). That's a paradox. The good manner is to provide a leaving function named, let's say, CloneL() to do the copy task.

This article is also published in www.NewLC.com
http://www.newlc.com/inside-cbase-class-six-essential-questions

【电力负荷分析】基于K-means聚类的多用户负荷分群与典型曲线建模 项目介绍 MATLAB 多用户负荷聚类预测|K-means分群与典型曲线建模(含模型描述及部分示例代码) 内容概要:本文介绍了一个基于MATLAB的多用户负荷聚类预测项目,旨在通过K-means算法对用户用电行为进行分群,并提取典型负荷曲线以提升预测精度。项目构建了完整的分析流程,涵盖数据生成、特征标准化、K-means聚类、典型曲线建模、分群预测建模及模型评价与可视化五大模块。采用模拟50000个样本、5个核心特征的数据集,综合考虑基础负荷、波动性、峰谷差、环境影响和周期性等因素,实现了从无监督聚类到有监督预测的闭环。通过轮廓系数等指标优选聚类数量,利用岭回归建立统一编码聚类标签的预测模型,并从整体与类别层面评估RMSE、MAE、MAPE和R²等指标,验证聚类对预测性能的提升作用。; 适合人群:具备一定MATLAB编程基础,从事电力系统分析、能源管理、负荷预测等相关领域的科研人员、工程师及研究生;熟悉基本统计建模与机器学习概念的技术人员。; 使用场景及目标:①应用于多用户电力负荷数据的用户行为分群与典型曲线提取;②用于提升负荷预测精度,支持需求响应、电网调度与能效管理决策;③作为教学案例展示K-means聚类与回归建模在实际工程中的集成应用;④为构建可复现、可扩展的能源数据分析流程提供模板。; 阅读建议:此资源强调全流程自动化与结果可复现,建议读者结合提供的代码逐步运行,重点关注数据标准化、聚类参数选择、标签编码方式及模型评价方法,同时可尝试替换为真实数据或扩展其他聚类与预测算法以深化理解。 立即下载

相关推荐

春秋BC532年世界历史地图矢量文件SHP格式.zip

本资源为《春秋BC532年世界历史地图矢量文件SHP格式》压缩包,文件大小约 1.86 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

Fdbus的一些记录

基于FDBus框架的CBaseWorker类通常会在一个独立的线程中执行工作任务。它的工作机制通常包括以下几个方面:1.:CBaseWorker通常会维护一个任务队列,用于存储需要执行的工作任务。当有新的任务到来时,会被加入到任务队列中。2.:CBaseWorker可能会使用事件循环机制,不断地从任务队列中取出任务,并执行相应的回调函数。这样可以保证任务按顺序得到执行,并且不会阻塞主线程。3.

weixin_43195445的博客 888

春秋BC482年世界历史地图矢量文件SHP格式.zip

本资源为《春秋BC482年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.26 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

fdbus普通client-server示例及接口说明

本篇是本人在学习fdbus过程中,为了厘清通信客户端和服务器之前的通信逻辑,以便后续回头看的时候能快速厘清。

sinat_18187903的博客 6548

春秋BC733年世界历史地图矢量文件SHP格式.zip

本资源为《春秋BC733年世界历史地图矢量文件SHP格式》压缩包,文件大小约 26.54 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

春秋BC764年世界历史地图矢量文件SHP格式.zip

本资源为《春秋BC764年世界历史地图矢量文件SHP格式》压缩包,文件大小约 26.64 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

CBase类的内幕 - 六个本质问题(英文)

 非常好的文章,建议所有symbian程序员仔细阅读!不知道有没有志愿者可以为大家翻译成中文啊?Inside CBase class - Six Essential QuestionsTutorial posted August 1st, 2007 by rensijie in Basics Platforms: Symbian OS Keywords: CBase Everybody knows

第三只眼的专栏 1145

战国BC272年世界历史地图矢量文件SHP格式.zip

本资源为《战国BC272年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.28 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

C++11中shared_ptr的使用

C++11中shared_ptr的使用

网络资源是无限的 8万+

ComfyUI/FLUX.3 Image Klein 服装印花白底提取

文件编号:c0233 输入带印花的服装照片,提取可独立展示的白底图案。实测从米色卫衣中提取深蓝燕子、橙色圆点和波纹,适合印花参考展示。 解压后将 c0233.json 导入 RunningHub 工作台。若在本地 ComfyUI 使用,请按已安装的节点和模型版本调整工作流。

ComfyUI/Qwen-Image 2.1 主体抠图与透明 PNG 输出

文件编号:c0192 输入一张带背景的照片,输出透明 PNG 和灰度遮罩,可用于商品素材叠图。实测去除了蕾丝礼服后的窗户和地面,保留裙摆轮廓与薄纱透明层次。 解压后将 c0192.json 导入 RunningHub 工作台。若在本地 ComfyUI 使用,请按已安装的节点和模型版本调整工作流。

BaseJob

using System; using System.Collections.Generic; using System.Linq; using System.Text; using WindowsFormsApplication3.Model; using WindowsFormsApplication3.Enums; using WindowsFormsApplica...

weixin_30735391的博客 340

春秋BC622年世界历史地图矢量文件SHP格式.zip

本资源为《春秋BC622年世界历史地图矢量文件SHP格式》压缩包,文件大小约 1.84 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

CBase类的内幕 - 六个本质问题

原文地址:http://www.cnjm.net/tech/article4202.html译者: 无牙老虎   http://blog.csdn.net/wenstory/archive/2008/05/25/2480097.aspx 每个人都知道Symbian中的C-class,是继承自CBase类,CBase在Symbian中被广泛的使用,因为它表示这样的

striker的专栏 1064

三甲医院十五五临床医学多模态大模型与科研数据隐私计算平台规划方案.pptx

三甲医院十五五临床医学多模态大模型与科研数据隐私计算平台规划方案.pptx

驱动级无痕hook技术-搞定CRC检测对抗

驱动级无痕hook技术-搞定CRC检测对抗

永磁同步电机新型非奇异快速终端滑模电流预测控制(Simulink仿真实现)

永磁同步电机新型非奇异快速终端滑模电流预测控制(Simulink仿真实现)内容概要:本文提出了一种针对永磁同步电机(PMSM)的新型非奇异快速终端滑模电流预测控制方法,并通过Simulink进行仿真实现。该方法结合了滑模控制的强鲁棒性与预测控制的动态响应优势,解决了传统滑模控制中存在的奇异性问题和稳态抖振现象,提升了电流环的动态性能与控制精度。文中详细阐述了控制器的设计过程,包括非奇异快速终端滑模面的构建、预测电流模型的建立以及控制律的推导,并在Simulink环境中搭建了完整的PMSM控制系统仿真模型,验证了所提方法在启动、负载突变等工况下的优越控制性能。; 适合人群:具备自动控制理论、电机控制及Simulink仿真基础的电气工程、自动化及相关专业的研究生、科研人员及工程师。; 使用场景及目标:①用于高性能电机驱动系统的设计与优化;②为滑模控制与预测控制的融合研究提供技术参考;③支持相关课题的仿真验证与算法开发。; 阅读建议:建议读者结合现代控制理论与电机控制基础知识,边阅读边在Simulink中复现仿真模型,重点关注滑模面设计与预测控制环节的实现细节,并通过对比实验深入理解所提方法的优势。

VCS HVP与验证计划planner:数字IC验证环境搭建与收敛实践

在数字IC验证中,VCS 是广泛使用的编译型仿真器,HVP 通常指面向硬件验证平台的高性能编译选项集,用于开启 SystemVerilog 类、随机约束和 NTB 等能力;planner 则指验证计划管理,核心是把功能点与测试用例、覆盖点建立映射。理解 VCS 先编译后仿真的原理,有助于优化增量编译、调试访问和覆盖率采集,提升回归收敛效率。规划驱动让激励不再散落,设计改版时能快速定位受影响用例,交接和覆盖率收敛更有依据。无论是 UVM 环境搭建、编译参数选择,还是验证计划表维护,都需要把工具选项与规划方法结

weixin_42543046的博客 345
上一篇: carbide.vs的debug问题
下一篇: carbide.vs调试技巧——缩减调试时间!
misuo
博客等级 码龄22年 4粉丝 21原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址