b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

zeromemory 头文件_zeromemory_zeromemory double

电脑杂谈  发布时间:2017-01-20 10:18:10  来源:网络整理

zeromemory double_zeromemory 头文件_zeromemory

zeromemoryzeromemory

It's completely different things. ZeroMemory macro fills a block of memory with zeros. Setting pointer to NULL... well it makes it pointing to nowhere.

Examples. Assume you have pointer p to object o of type "Type":

struct Type
{
    int i;
    float f;
    bool b;
};
Type o;
Type* p = &o;

// In memory that will be something like this:
// "o" internals = [010101010001010010110010010010100011001001010000011...]
// "p" address = 0x00830748
//(number of bits and hex adress is just example)

If you ZeroMemory it:

ZeroMemory(&o, sizeof(o));
// ---- or -----
ZeroMemory(p, sizeof(o));

// In memory we will have:
// "o" internals = [000000000000000000000000000000000000000000000000000...]
// "p" address = 0x00830748

zeromemory 头文件_zeromemory double_zeromemory

All variables inside o is now has value of zero:

cout << o.i; // 0
cout << o.f; // 0.0f
cout << o.b; // false

cout << p->i; // 0
cout << p->f; // 0.0f
cout << p->b; // false

If you NUll-ify pointer:

p = NULL;
// In memory we now have:
// "o" internals = [010101010001010010110010010010100011001001010000011...]
// "p" address = 0x00000000

If now you dereference p you will get undefined behavior:

zeromemory double_zeromemory_zeromemory 头文件

int a = p->i; // Access voilation reading location 0x00000000

If you NUll-ify object:It will not compile, if Type don't have overloaded operator=()

o = NULL; // error C2679: binary '=' : no operator found 
          // which takes a right-hand operand of type 'int' 
          // (or there is no acceptable conversion)

Applying it to DirectX

When you using DirectX, you must fill-in some structs to pass them to API functions. Here is where the magic. You can ZeroMemoryit to values of 0, which is mostly default ones, and then just fill-in needed values, simplifying your code and keeping you from mistakes with strange values (if you create object and will not set some member variable, it will contain garbage value).


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27562-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...