商业生存

Featured

“There are three ways to make a living in this business: be first, be smarter, or cheat.”

“商业世界里只有三种生存模式,更快、更聪明,或者更会骗人。”

– 美国电影《商海通牒》

Why doesn’t delete zero out its operand?

Consider

	delete p;
	// ...
	delete p;

If the … part doesn’t touch p then the second “delete p;” is a serious error that a C++ implementation cannot effectively protect itself against (without unusual precautions). Since deleting a zero pointer is harmless by definition, a simple solution would be for “delete p;” to do a “p=0;” after it has done whatever else is required. However, C++ doesn’t guarantee that.One reason is that the operand of delete need not be an lvalue. Consider:

	delete p+1;
	delete f(x);

Here, the implementation of delete does not have a pointer to which it can assign zero. These examples may be rare, but they do imply that it is not possible to guarantee that “any pointer to a deleted object is 0.” A simpler way of bypassing that “rule” is to have two pointers to an object:

	T* p = new T;
	T* q = p;
	delete p;
	delete q;	// ouch!

C++ explicitly allows an implementation of delete to zero out an lvalue operand, and I had hoped that implementations would do that, but that idea doesn’t seem to have become popular with implementers.If you consider zeroing out pointers important, consider using a destroy function:

	template<class T> inline void destroy(T*& p) { delete p; p = 0; }

Consider this yet-another reason to minimize explicit use of new and delete by relying on standard library containers, handles, etc.

Note that passing the pointer as a reference (to allow the pointer to be zero’d out) has the added benefit of preventing destroy() from being called for an rvalue:

	int* f();
	int* p;
	// ...
	destroy(f());	// error: trying to pass an rvalue by non-const reference
	destroy(p+1);	// error: trying to pass an rvalue by non-const reference

测试 USB 网卡连接 GigE 相机

轻薄笔记本没有有线网卡,无法连接 GigE 相机,LT 于是将目光转向USB网卡。

测试了两种 USB 网卡:

  • 1000M USB 网卡,芯片 AX88179,VisionPro 会出错。放弃。
  • 2.5G USB 网卡,芯片 RTL8156 ,2.5Gbps。GigE 相机采用 9K 帧 和 1500 的内部延迟,VisionPro 里自由运行,连续采图 593702 幅(2592*1944), 没有报错。

隔几天又测试了几次,感觉很稳定,没有报错。问题解决。

如果你用其他芯片的USB网卡并且可用,欢迎评论区留言分享你的信息。

[翻译] Qt 图形视图框架 – Graphics View Framework

翻译

参见:https://doc.qt.io/qt-5/graphicsview.html

Qt 的图形视图,提供了一个界面用来管理大量2D图形项目;一个视图部件用来可视化这些图像项目,支持缩放和旋转。这个框架包括一个事件传播体系结构,该体系结构对场景中的项目进行精度和双精度交互功能。项目可以处理按键事件。鼠标按下、移动、释放和双击事件,他们还可以耿总鼠标的移动。图形视图使用BSP树提供了非常快速的项目检索功能,因此它可以实时可视化大型场景,甚至包括数百万的项目。

Continue reading

睿登电源外壳DIY

材料准备

  • 睿登电源面板
  • 明纬电源
  • 品字电源插座(带保险管)
  • 提手
  • 压线端子
  • 连接线
  • 3D打印机

获取尺寸 -> 设计外壳数模 -> 3D打印 -> 装机验证 -> 修正 -> 成品。