开发者

How to assign NULL to a pointer in unsafe code?

开发者 https://www.devze.com 2023-03-14 08:00 出处:网络
Please, can anybody tell me how to assign null to a pointer in this type unsafe code 开发者_运维知识库example...

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

精彩评论

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

关注公众号