这是标准的c ++ ...... [英] Is this standard c++...

查看:56
本文介绍了这是标准的c ++ ......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将这种技术应用于所有本地技术。内存池

我发明了一种特殊的多线程分配器算法。关于

的更多信息可以在这里找到:

http://groups.google.com/group/comp....c40d42a04ee855


无论如何,这是代码片段:


#include< cstdio>

#include< cstddef>

#include<新>

模板< size_t T_sz>

class lmem {

unsigned char m_buf [T_sz];

public :

void * loadptr(){

返回m_buf;

}

};

class foo {

public:

foo(){printf("(%p)foo :: ~foo()",(void *)这个); }

~foo(){printf("(%p)foo :: ~foo()",(void *)this); }

};

int main(无效){

foo * f;

lmem< sizeof(* f)foomem;

f = new(foomem.loadptr())foo;

f-> ~foo();

返回0 ;

}

I am thinking about using this technique for all the "local" memory pools in
a paticular multi-threaded allocator algorithm I invented. Some more info on
that can be found here:

http://groups.google.com/group/comp....c40d42a04ee855

Anyway, here is the code snippet:

#include <cstdio>
#include <cstddef>
#include <new>
template<size_t T_sz>
class lmem {
unsigned char m_buf[T_sz];
public:
void* loadptr() {
return m_buf;
}
};
class foo {
public:
foo() { printf("(%p)foo::~foo()", (void*)this); }
~foo() { printf("(%p)foo::~foo()", (void*)this); }
};
int main(void) {
foo *f;
lmem<sizeof(*f)foomem;
f = new (foomem.loadptr()) foo;
f->~foo();
return 0;
}

推荐答案

Chris Thomasson写道:
Chris Thomasson wrote:

我正在考虑将这种技术用于所有本地的内存

池中我发明了一个特定的多线程分配器算法。

更多信息可以在这里找到:

http://groups.google.com/group/comp .. ..c40d42a04ee855


无论如何,这里是代码片段:


#include< cstdio>

#include< cstddef>

#include< new>


模板< size_t T_sz>

class lmem {

unsigned char m_buf [T_sz];

public:

void * loadptr(){

return m_buf ;

}

};


class foo {

public:

foo(){printf("(%p)foo :: ~foo()",(void *)this); }
I am thinking about using this technique for all the "local" memory
pools in a paticular multi-threaded allocator algorithm I invented.
Some more info on that can be found here:

http://groups.google.com/group/comp....c40d42a04ee855

Anyway, here is the code snippet:

#include <cstdio>
#include <cstddef>
#include <new>
template<size_t T_sz>
class lmem {
unsigned char m_buf[T_sz];
public:
void* loadptr() {
return m_buf;
}
};
class foo {
public:
foo() { printf("(%p)foo::~foo()", (void*)this); }



字符串似乎不正确。

The string seems to be incorrect.


~foo(){printf("( %p)foo :: ~foo()",(void *)this); }

};


int main(无效){

foo * f;

lmem< ; sizeof(* f)foomem;

f = new(foomem.loadptr())foo;
~foo() { printf("(%p)foo::~foo()", (void*)this); }
};
int main(void) {
foo *f;
lmem<sizeof(*f)foomem;
f = new (foomem.loadptr()) foo;



这不是不正确,但我相信你可能有问题

对齐。只有从免费商店获得的大小''sizeof(foo)''
的内存块才能正确对齐,以便在其中构建一个''foo''


It''s not "incorrect", but I believe you may have a problem
with alignment. Only a memory block sized ''sizeof(foo)''
obtained from free store is aligned correctly to have a ''foo''
constructed in it like that.


f-> ~foo();

返回0;

}
f->~foo();
return 0;
}



V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


Chris Thomasson写道:
Chris Thomasson wrote:

我正在考虑将这种技术用于所有本地的内存池

我发明了一种特殊的多线程分配器算法。关于

的更多信息可以在这里找到:

http://groups.google.com/group/comp....c40d42a04ee855


无论如何,这是代码片段:


#include< cstdio>

#include< cstddef>

#include< new>


模板< size_t T_sz>

class lmem {

unsigned char m_buf [T_sz];
I am thinking about using this technique for all the "local" memory pools in
a paticular multi-threaded allocator algorithm I invented. Some more info on
that can be found here:

http://groups.google.com/group/comp....c40d42a04ee855

Anyway, here is the code snippet:

#include <cstdio>
#include <cstddef>
#include <new>
template<size_t T_sz>
class lmem {
unsigned char m_buf[T_sz];



您可能会因使用unsigned char数组而遇到对齐问题,

您应遵循与malloc相同的系统特定对齐规则。

You may run into alignment problems by using an array of unsigned char,
you should follow the same system specific alignment rules as malloc.


public:

void * loadptr(){

return m_buf;

}

};


class foo {

public:

foo(){printf ("(%p)foo :: ~foo()",(void *)this); }

~foo(){printf("(%p)foo :: ~foo()",(void *)this); }

};
public:
void* loadptr() {
return m_buf;
}
};
class foo {
public:
foo() { printf("(%p)foo::~foo()", (void*)this); }
~foo() { printf("(%p)foo::~foo()", (void*)this); }
};



C ++纯粹主义者避免使用printf。切勿将其与iostream混合使用。

C++ purists avoid printf. Never mix it with iostreams.


>

int main(void){
>
int main(void) {



Just int main()是C ++中的常态。


-

Ian Collins。

Just int main() is the norm in C++.

--
Ian Collins.


Ian Collins写道:

Ian Collins wrote:


C ++纯粹主义者避免使用printf。切勿将其与iostream混合使用。
C++ purists avoid printf. Never mix it with iostreams.



Bah。毫无意义的教条。有时它是正确的。


Brian

Bah. Pointlessly dogmatic. Sometimes it''s the right thing.


Brian


这篇关于这是标准的c ++ ......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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