简体   繁体   English

weak_ptr 的自定义分配器

[英]Custom allocator for weak_ptr

From high CPU usage in RtlpLowFragHeapAllocFromContext() I am making a guess that std::weak_ptr() that I use frequently (calling .lock() on it) should be the culprit that doesn't use the internal efficient memory pool, but rather resorts to malloc() / free() / new / delete guys.RtlpLowFragHeapAllocFromContext()中的高 CPU 使用率来看,我猜测我经常使用的std::weak_ptr() (在其上调用.lock() )应该是不使用内部高效 memory 池的罪魁祸首,而是诉诸malloc() / free() / new / delete家伙。

Is there a way to specify custom allocator for an std::weak_ptr ?有没有办法为std::weak_ptr指定自定义分配器? If yes, how?如果是,如何? If no, why?如果不是,为什么?

UPDATE: uploading the profiler snapshot更新:上传分析器快照探查器快照

weak_ptr does not allocate memory, nor do any of its operations (which are all noexcept ). weak_ptr不分配 memory,也没有它的任何操作(都是noexcept )。 It does its job based on allocations which are part of any shared_ptr 's control block.它基于作为任何shared_ptr控制块一部分的分配来完成其工作。 You can customize shared_ptr 's control block allocation behavior, but that's got nothing to do with weak_ptr itself.您可以自定义shared_ptr的控制块分配行为,但这与weak_ptr本身无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM