English 中文(简体)
能否在C++模板中强行规定一个毗连的分配边界?
原标题:Can a contiguous allocation boundary be forced in a C++ template?

简单例子:

template <class P> class MyT
{
    struct Item
    {
    public:
        Item() {}
        P *pData;
        Item *next;
    };
    Item *head;
public:
    ...adding etc..
    P* operator [](int index)
    {
       See question below:
    }
};

我一定能够确保以我能够计算所抵消的以下方式分配项目:(@Steve:) 或许在这里不很清楚;我所需要的是快速和方便的;在不连续10 000次的情况下,很容易找到该项目。

Item *pi = head + (sizeof(Item) * (index - 1));

A (clearer?) 解释

最佳回答
问题回答

我猜想你们需要的是:先入或 st:主。

然而,如果你为项目分配了连续的记忆,那么你将做些什么工作,而头部则指出,开端与Yussarian所建议的修改。

如果跨越这一限制,在开始时,你可以预先发言,将更多内容分配给这个领域,并删除现有的内容。

注:所有这些物品都在集装箱内包装给你。

可通过特殊关键词强制实行“双重婚姻”。

http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html#Variable-Attributes

审视“调整”

如果我正确理解你的问题,你需要超越<条码>的新,<条码> 项目你将永远需要(一般情况下是可能的,但在具体情况下可能是可能的)。 然后,每当安装一个<代码>Item时,分配人将返回预定分配区下一个位置。

所有这些都看上去不现实,简单的解决办法是使用<条码>。

Item* pi = (head + (index - 1));

工作。 此前,你们是否希望这样做? <代码>结构 项目视同联系名单结构(内容<编码>next)。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签