内存分配器&正确对齐...... [英] memory allocators & proper alignment...
问题描述
以下是我正在研究的C ++分配器原型的一些信息:
http://groups.google.com/group/comp....eee1f61fdbb52c
任意尝试真实的技术来计算用户可以抛出的任何用户的C ++类型的正确对齐方式吗?对于初始代码,我假设
对齐(T)== sizeof(T)......现在我已经非常接近能够发布
了这件事,我希望能够拼凑出这个松散的结局。
我所使用的所有分配器总是被实体使用,这些实体是
私有的库实现......任何他们只需要在二级缓存行边界上对齐
结构。所以,我不需要对齐
类型,我只调整缓存行。
现在我需要弄清楚如何得到任何C ++类型的正确对齐
用户可以想出...
帮助!
:^)
-
Chris M. Thomasson
http://appcore.home.comcast.net
Here is some info on a C++ allocator prototype I am working on:
http://groups.google.com/group/comp....eee1f61fdbb52c
Any tried-and-true techniques for calculating the correct alignment of any
C++ type the user can throw at it? For the initial code, I was assuming that
the alignment(T) == sizeof(T)... Now that I am so close to being able to
release this thing, I wanted to be able to stitch up this loose end.
All of the allocators I have worked on were always uses by entities which
were private to a library implementation... Any they only needed to align
structures on level-2 cache-line boundaries. So, I didn''t need to align for
the type, I only align for the cache line.
Now I need to figure out how to get the correct alignment of any C++ type a
user can come up with...
Help!
:^)
--
Chris M. Thomasson
http://appcore.home.comcast.net
推荐答案
" Chris Thomasson < cr ***** @ comcast.netwrote in message
news:mJ ************************* *****@comcast.com。 ..
"Chris Thomasson" <cr*****@comcast.netwrote in message
news:mJ******************************@comcast.com. ..
以下是我正在研究的C ++分配器原型的一些信息:
http://groups.google.com/group/comp....eee1f61fdbb52c
[...]
[...]
现在我需要弄清楚如何获得正确的任何C ++类型的对齐
a用户可以拿出...
Now I need to figure out how to get the correct alignment of any C++ type
a user can come up with...
我想我会继续发布今天的代码或明天。
I think I will just go ahead and post the code today or tomorrow.
Chris Thomasson写道:
Chris Thomasson wrote:
这是关于C ++分配器原型的一些信息我正在努力:
http://groups.google.com/group/comp....eee1f61fdbb52c
任何尝试过的-true技术用于计算用户可以投入的任何C ++类型的正确对齐方式?b
对于初始代码,我是
假设对齐(T)== sizeof(T)......现在我已经非常接近了
能够发布这件事,我希望能够将这个
松散结束。
我所做的所有分配器总是被实体使用
是库实现的私有...任何他们只需要
来对齐二级缓存行边界上的结构。所以,我不需要
来对齐类型,我只对齐缓存行。
现在我需要弄清楚如何得到任何C ++
类型的正确对齐用户可以想出...
帮助!
:^)
Here is some info on a C++ allocator prototype I am working on:
http://groups.google.com/group/comp....eee1f61fdbb52c
Any tried-and-true techniques for calculating the correct alignment of
any C++ type the user can throw at it? For the initial code, I was
assuming that the alignment(T) == sizeof(T)... Now that I am so close to
being able to release this thing, I wanted to be able to stitch up this
loose end.
All of the allocators I have worked on were always uses by entities
which were private to a library implementation... Any they only needed
to align structures on level-2 cache-line boundaries. So, I didn''t need
to align for the type, I only align for the cache line.
Now I need to figure out how to get the correct alignment of any C++
type a user can come up with...
Help!
:^)
在标准C ++中没有可靠的计算方法。我记得
阅读几乎总能奏效的技巧。这篇文章似乎是描述其中一个(尽管它对我没有任何影响)。
http://www.monkeyspeak.com/alignment/
john
There is no infallible way to compute that in standard C++. I recall
reading about techniques that almost always work. This article seems to
describe one of those (although it doesn''t ring any bells for me).
http://www.monkeyspeak.com/alignment/
john
5月17日上午11:02,Chris Thomasson < cris ... @ comcast.netwrote:
On May 17, 11:02 am, "Chris Thomasson" <cris...@comcast.netwrote:
" Chris Thomasson" < cris ... @ comcast.netwrote in message
新闻:mJ *********************** *******@comcast.com。 ..
"Chris Thomasson" <cris...@comcast.netwrote in message
news:mJ******************************@comcast.com. ..
以下是我正在处理的C ++分配器原型的一些信息:
Here is some info on a C++ allocator prototype I am working on:
http://groups.google.com/group/ comp .... / thread / beeee1 ...
http://groups.google.com/group/comp..../thread/beeee1...
[...]
[...]
现在我需要弄清楚如何正确对齐任何C ++类型
a用户可以想出...
Now I need to figure out how to get the correct alignment of any C++ type
a user can come up with...
单程:
模板< typename T>
struct alignof_static
{
struct Helper1 {T v; };
struct Helper2 {char c; Helper1 v; };
static const unsigned value = sizeof(Helper2)-sizeof(Helper1);
};
template< typename T>
unsigned alignof()
{
return alignof_static< T> :: value;
}
#ifdef __GNUC__
struct X
{
int a;
} __attribute __((aligned(8)));
#else
typedef int X;
#endif
#include< iostream>
int main()
{
std :: cout<< alignof< char>()<< " \ n";
std :: cout<< alignof< short>()<< " \ n";
std :: cout<< alignof< int&>()<< " \ n";
std :: cout<< alignof< char&>()<< " \ n";
std :: cout<< alignof< X>()<< " \ n";
}
one way:
template <typename T>
struct alignof_static
{
struct Helper1 { T v; };
struct Helper2 { char c; Helper1 v; };
static const unsigned value = sizeof(Helper2)-sizeof(Helper1);
};
template <typename T>
unsigned alignof()
{
return alignof_static<T>::value;
}
#ifdef __GNUC__
struct X
{
int a;
} __attribute__ ((aligned (8)));
#else
typedef int X;
#endif
#include <iostream>
int main()
{
std::cout << alignof<char>() << "\n";
std::cout << alignof<short>() << "\n";
std::cout << alignof<int &>() << "\n";
std::cout << alignof<char &>() << "\n";
std::cout << alignof<X>() << "\n";
}
这篇关于内存分配器&正确对齐......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!