Topic: Support for alignment and memory allocation


Author: Mathias Gaunard <loufoque@gmail.com>
Date: Tue, 3 Jul 2007 08:48:35 CST
Raw View
The proposal for adding alignment support to the C++ programming
language (N2301) says that new should provide memory with an alignment
that shall be an integral multiple of the strictest fundamental
alignment requirement of any object type.

However, given that one can easily, with this proposal, define the
alignment of a type to be extremely big, that doesn't seem to be
doable.

Implementations on x86 linux, for example, usually provide memory with
an alignment of 8.
Types, with that proposal, can however be defined to have an arbitrary
alignment, technically up to 2^32 - 1. (However, 16, 32, 64, 128 and
256 are probably the only used ones).

The only good way I see to fix that issue is that operator new/
operator new[] knows about the alignment required for the type for
which memory is being allocated.
operator delete/operator delete[] could also know it (which would help
in making efficient implementations) since in C++, the same type as
the type used with new must be used with delete, unless the type used
with delete is a base of the other and has a virtual destructor.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: jam <farid.mehrabi@gmail.com>
Date: Fri, 6 Jul 2007 13:38:29 CST
Raw View
On Jul 3, 6:48 pm, Mathias Gaunard <loufo...@gmail.com> wrote:
> The proposal for adding alignment support to the C++ programming
> language (N2301) says that new should provide memory with an alignment
> that shall be an integral multiple of the strictest fundamental
> alignment requirement of any object type.
>
> However, given that one can easily, with this proposal, define the
> alignment of a type to be extremely big, that doesn't seem to be
> doable.
>
> Implementations on x86 linux, for example, usually provide memory with
> an alignment of 8.
> Types, with that proposal, can however be defined to have an arbitrary
> alignment, technically up to 2^32 - 1. (However, 16, 32, 64, 128 and
> 256 are probably the only used ones).
>
> The only good way I see to fix that issue is that operator new/
> operator new[] knows about the alignment required for the type for
> which memory is being allocated.
> operator delete/operator delete[] could also know it (which would help
> in making efficient implementations) since in C++, the same type as
> the type used with new must be used with delete, unless the type used
> with delete is a base of the other and has a virtual destructor.
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html                     ]

I think this(alignment) needs some changes to the type information
mechanism of C++. But a type awar  memory allocation mechanism(in
contrary to the existing size awar operator new which is too limited)
could benefit C++ a lot ; specifically in defining auto-deleting smart
pointers.

regards,
FM.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]