_Expand与new与GNU [英] _Expand versus new versus GNU

查看:127
本文介绍了_Expand与new与GNU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我成了一个新朋友。他的名字是 _expand ,我们进行了一些不错的对话,我甚至和他一起出去过几次。但是当我开始询问时,没有人听说过我的_expand。我变得可疑。我在微软打电话给几个完全不隐喻的朋友,在商家的其他地方打了几个朋友。没有。没有人曾经使用过它。我围着各种搜索引擎和源代码树。没有什么,除了粗略提及这里和那里。当然没有足够的性能和兼容性的信息,以便将_expand引入生产代码或更贴切地,通用库。

Recently, I made a new friend. His name is _expand, and we've had some nice conversations, and I've even hung out with him a few times. But when I started asking around, no one had ever heard of my _expand. I became suspicious. I called a few thoroughly non-metaphorical friends at microsoft, and a few friends elsewhere in the business. Nothing. No one had ever used it. I noodled around various search engines and source trees. Nothing except a cursory mention here and there. Certainly not enough information on performance and compatibility for me to introduce _expand into production code or more pertinently, generic libraries.

更糟糕的是,没有相当的功能,我可以在任何gnu库中找到,所以我入侵我的新朋友不会是可移植的最小。这是一个耻辱,因为它真的是一个迷人和令人兴奋的能力。当然,我可以挖掘到realloc,并分开它的功能,但问题是,大部分的实现是高度可变的* nixes。所以我必须代码版本后版本尝试,并获得一个便携式_expand。仍然,似乎可笑的是,没有类似的存在于glib或扩展的gnu libs。

Worse, there's no equivalent function that I can find in any of the gnu libraries, so anything I hack up with my new friend isn't going to be portable in the least. Which is a shame, because it's really a fascinating and exciting capacity to have. Certainly, I could dig down into realloc, and pull apart how it functions, but the problem there is that much of the implementation is highly variable on *nixes. So I'd have to code version after version to try and get a portable _expand. Still, it seems ridiculous that nothing similar exists in the glib or the expanded gnu libs.


  1. 是否有类似的功能,我应该知道的关于linux黑客? 已回复的问题

  2. 有没有标准的钩子,我可以构建一个类似的函数? 已回答

  3. 有人知道_expand提供哪种性能?

  4. 如何与LFH上分配的对象进行互动?

  1. Is there a similar function that I should know about for linux hacking? Mostly Answered
  2. Is there a standard hook that I could build a similar function on? Answered
  3. Does anyone know what kind of performance _expand offers?
  4. How does it interact with objects allocated on the LFH?

我试图构建一个单链接累加器扩展,以尽量减少碎片,同时分配多元素块沿着传统的deque实现的线。通过约束元素添加和删除的用例,我希望优化整个结构的时间删除,以及元素插入和索引。因此,_expand的大失败让我可以让结构智能地思考什么时候,如果它可以在现场调整大小,这意味着它可以把数据放在哪里。

To clarify my interests, I'm trying to build a singly-linked accumulator that expands in an attempt to minimize fragmentation while allocating multiple-element blocks along the lines of the traditional deque implementation. By constraining the use-cases for element addition and deletion, I'm hoping to optimize time-to-delete for the whole structure, as well as element insertion and indexing. As a result, the "loud failure" of _expand lets me make the structure think intelligently about when and if it can resize inplace, and what that means about where it can put data.

推荐答案

该C ++已经通过删除任何等效的 realloc 显示这些东西少多关注。不令人吃惊的 _expand 在很大程度上被忽略,当它甚至不是一直可用在操作系统级别。如果你想滚动自己的,有很多先例,用户定义版本的malloc,和快速看看/usr/include/malloc.h在我的Linux框显示钩子显式为此...

That C++ has been getting by with new and delete sans any equivalent of realloc shows how little attention these things get. Unsurprising _expand is largely ignored when it's not even consistently available at the OS level. If you want to roll your own, there's plenty of precedent for user-defined versions of malloc, and a quick look in /usr/include/malloc.h on my Linux box shows hooks explicitly for this...

/* Called once when malloc is initialized; redefining this variable in
   the application provides the preferred way to set up the hook
   pointers. */
extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
/* Hooks for debugging and user-defined versions. */
extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
                                        __const __malloc_ptr_t));
extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
                                                    __const __malloc_ptr_t));
extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
                                                     size_t __size,
                                                     __const __malloc_ptr_t));
extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __alignment,
                                                       size_t __size,
                                                      __const __malloc_ptr_t));
extern void (*__after_morecore_hook) __MALLOC_PMT ((void));

看起来不像你能拦截现有的 在特定的决策点实现,或者很容易得到洞察它是否会在现场调整大小,所以你可能必须重新实现一切(或适应任何现有的堆实现)。

Doesn't look like you'll be able to intercept the existing realloc implementation at that particular decision point though, or easily get insight into whether it will resize inplace, so you might have to reimplement everything (or adapt any of many existing heap implementations).

这篇关于_Expand与new与GNU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆