Rafael Espindola
2008-Aug-28 13:42 UTC
[LLVMdev] is the SmallVector implementation standard c++?
While debugging a bootstrap problem, I noticed that SmallVector stores one element in SmallVectorImpl and N - 1 in SmallVector. It also assumes that all elements are continuous in memory. Does C++ makes any guaranties about the relative memory position of a base and parent classes? I haven't studied it a lot, maybe we can keep N elements in SmallVector and pass the pointer to SmallVectorImpl constructor? Cheers, -- Rafael Avila de Espindola Google | Gordon House | Barrow Street | Dublin 4 | Ireland Registered in Dublin, Ireland | Registration Number: 368047
David Vandevoorde
2008-Aug-28 14:02 UTC
[LLVMdev] is the SmallVector implementation standard c++?
On Aug 28, 2008, at 9:42 AM, Rafael Espindola wrote: [...]> Does C++ makes any > guaranties about the relative memory position of a base and parent > classes?The C++ standard doesn't make such guarantees. (Particular implementations may.) Daveed
Hi, in simple-inheritance the base object is always allocated first, and because of the union of double, long long, etc... the first element is aligned, so the others will be contigous. It's a bit tricky but should work always... 2008/8/28 Rafael Espindola <espindola at google.com>> While debugging a bootstrap problem, I noticed that SmallVector stores > one element in SmallVectorImpl and N - 1 in SmallVector. It also > assumes that all elements are continuous in memory. Does C++ makes any > guaranties about the relative memory position of a base and parent > classes? > > I haven't studied it a lot, maybe we can keep N elements in > SmallVector and pass the pointer to SmallVectorImpl constructor? > > Cheers, > -- > Rafael Avila de Espindola > > Google | Gordon House | Barrow Street | Dublin 4 | Ireland > Registered in Dublin, Ireland | Registration Number: 368047 > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080829/ce41fa1f/attachment.html>
Chris Lattner
2008-Aug-28 22:55 UTC
[LLVMdev] is the SmallVector implementation standard c++?
On Aug 28, 2008, at 6:42 AM, Rafael Espindola wrote:> While debugging a bootstrap problem, I noticed that SmallVector stores > one element in SmallVectorImpl and N - 1 in SmallVector. It also > assumes that all elements are continuous in memory. Does C++ makes any > guaranties about the relative memory position of a base and parent > classes?It isn't guaranteed, but true of every implementation I know of.> I haven't studied it a lot, maybe we can keep N elements in > SmallVector and pass the pointer to SmallVectorImpl constructor?If this would make SmallVector bigger and slower, then I think we should wait for an implementation that requires it. If it is just a minor internal tweak, plz go for it. -Chris
On Thu, Aug 28, 2008 at 18:32, Julio <julio.martin.hidalgo at gmail.com> wrote:> Hi, in simple-inheritance the base object is always allocated first, and > because of the union of double, long long, etc... the first element is > aligned, so the others will be contigous. It's a bit tricky but should work > always... >Alignment is probably correct, but since access to the memory is through a T* but the memory is declared as a char (in GCC) or a union (elsewhere), I suspect it's technically in violation of the strict aliasing rules. Since the SmallVectorImpl constructor sets the 3 pointers, it should be possible to pass in the begin pointer as well as the size, and remove the hacks. Also, the comment the says "Default ctor - Initialize to empty." should probably be changed, since it's not a default constructor. Basing all this off a quick peek at http://llvm.cs.uiuc.edu/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?revision=55181&view=markup , ~ Scott
Mike Stump
2008-Aug-28 23:42 UTC
[LLVMdev] is the SmallVector implementation standard c++?
On Aug 28, 2008, at 6:42 AM, Rafael Espindola wrote:> It also assumes that all elements are continuous in memory. Does C++ > makes any guaranties about the relative memory position of a base > and parent classes?They are inside a continuous sequence of bytes that comprise the complete object.
Possibly Parallel Threads
- [LLVMdev] is the SmallVector implementation standard c++?
- [ADT] Adding instrumentation for ASAN to SmallVector
- Crash in SmallVector with latest MSVC 2019 (debug mode)
- [LLVMdev] Question about SmallVector implementation detail
- [LLVMdev] Question about SmallVector implementation detail