零记忆 [英] zero memory
问题描述
在
结构上调用operator new之后将C ++方法清零的原因是什么?
在这种情况下,构造函数不可能也不可能一个类,因为
人们使用我的代码c-stlye将指向
结构的第一个成员的指针转换为稍后在代码中指向entrire结构的指针。
What is the C++ way to zero out memory after calling operator new on a
struct?
A constructor is not possible in this case nor is a class, because the
people using my code c-stlye cast a pointer to the first member of the
struct to a pointer to the entrire struct later on in the code.
推荐答案
Christopher Pisz写道:
Christopher Pisz wrote:
什么是C ++归零方法在
结构上调用operator new之后的内存?
What is the C++ way to zero out memory after calling operator new on a
struct?
要清零什么内存?什么在结构上调用operator new
是什么意思?你能发贴代码而不是英文吗?
To zero out what memory? What does "calling operator new on a struct"
mean? Could you post code instead of English?
在这种情况下,构造函数是不可能也不是类,因为
的人使用我的代码c-stlye将指向
结构的第一个成员的指针转换为稍后在代码中指向entrire结构的指针。
A constructor is not possible in this case nor is a class, because the
people using my code c-stlye cast a pointer to the first member of the
struct to a pointer to the entrire struct later on in the code.
嗯?
V
-
请在通过电子邮件回复时删除资本''A'
我没有回复最热门的回复,请不要问
Huh?
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
Christopher Pisz写道:
Christopher Pisz wrote:
在
a struct上调用operator new之后,将内存清零的C ++方法是什么?
What is the C++ way to zero out memory after calling operator new on
a struct?
你为什么这么想?这解决了什么问题?
Why do you want to? What problem does this solve?
在这种情况下,构造函数不可能也不是类,因为
使用我的代码的人c -stlye将指向结构的第一个成员
的指针转换为稍后在代码中指向entrire结构的指针。
A constructor is not possible in this case nor is a class, because
the people using my code c-stlye cast a pointer to the first member
of the struct to a pointer to the entrire struct later on in the code.
如果它是POD,你可以使用memcpy将整个东西设置为
all-bits-zero。那并不总是你想要的,坦白说通常是
a糟糕的设计。
Brian
If it''s a POD, you can use memcpy to set the whole thing to
all-bits-zero. That''s not always what you want, and frankly is usually
a poor design.
Brian
Victor Bazarov写道:
Victor Bazarov wrote:
Christopher Pisz写道:
Christopher Pisz wrote:
>>什么是在一个
结构上调用operator new之后C ++将内存清零的方法?
>>What is the C++ way to zero out memory after calling operator new on a
struct?
把内存归零?什么在结构上调用operator new
是什么意思?你可以发贴代码而不是英文吗?
To zero out what memory? What does "calling operator new on a struct"
mean? Could you post code instead of English?
>>在这种情况下,构造函数不可能也不是类,因为
使用我的代码的人c-stlye将指向
结构的第一个成员的指针转换为稍后在代码中指向entrire结构的指针。
>>A constructor is not possible in this case nor is a class, because the
people using my code c-stlye cast a pointer to the first member of the
struct to a pointer to the entrire struct later on in the code.
嗯?
Huh?
我猜,但是Pisz先生可能会因为知道这样做而受益:
struct A
{
int X;
int Y;
char Z [30];
//其他POD成员......
};
A x = A();
I''m guessing but Mr Pisz could probably benefit from knowing what this does:
struct A
{
int X;
int Y;
char Z[30];
// other POD members ...
};
A x = A();
这篇关于零记忆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!