开发者

How to assign NULL to a pointer in unsafe code?

Please, can anybody tell me how to assign null to a pointer in this type unsafe code 开发者_运维知识库example...

public  struct Chunck
{
            unsafe
           public tag *start;
            unsafe
           public tag *end;

}

class  HeapManager
{
    public int HeapMemorySize = 1000;
    public int sizeAllcated = 0;
    unsafe
    Chunck *Header;
    HeapManager()
    {
        unsafe
        {// this is not happening as compare to C langauge its allowed ??
            Header =(Chunck*) NULL;
        }
    }
}


It couldn't be simpler

Header = null;


Just don't bother. Unlike the C runtime, the CLR promises to zero-initialize all fields of a class when it is created. Which automatically makes the Header member null.

Don't write heap managers in C#, please.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜