c#中的动态内存管理 [英] dynamic memory manage in c#

查看:70
本文介绍了c#中的动态内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#



i want do like that code in c#

node=(struct student *)new(struct student);



节点是指针,我想做那个工作


node is pointer and i want to do that job

推荐答案

你通常不会在C#中使用指针 - 你可以,但只能 不安全代码 [ ^ 并且很难做到。



除非你在C#和外部非.NET代码之间传递数据,否则你需要认真的性能调整它是一个非常好的馊主意。改为使用引用:

You don't normally use pointers in C# - you can, but only in unsafe code[^] and it is deliberatly difficult to do.

Unless you are passing data between C# and external non-.NET code, or you need serious performance tuning it is a very bad idea. use a reference instead:
Student node = new Student();

并让系统为您排序。


using System.Runtime.InteropServices;




node=(student *)Marshal.AllocHGlobal(sizeof(student));



这正是我想要的和它的真实


this is exactly what i want and its true


这篇关于c#中的动态内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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