VC6中的长指针初始化 [英] long pointer initialization in VC6

查看:83
本文介绍了VC6中的长指针初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC6中有一个程序。我有一个整数变量和一个长指针如下



int x = 50;

long * y;

y = new long [x];



y的初始化有什么问题,因为我的内存泄漏了。请提供一些帮助。

I have a program in VC6. There I have an integer variable and a long pointer as follows

int x = 50;
long *y;
y = new long[x];

Is there anything wrong in the initialization for y, because i am getting memory leak it. Pls provide some help.

推荐答案

y不是长指针,而是指向 long 的指针;但也许你的意思是。



表达式

y is not a long pointer, but a pointer to a long; but perhaps you meant that.

The expression
new long[x]



分配一个x元素数组,每个元素的类型为 long 并返回指向第一个元素的指针。因此答案是:不,将指针存储在y中没有任何问题。



内存泄漏可能是由于您忘记释放内存空间再次。在程序的某个地方你应该有一个声明,比如


allocates an array of x elements each of type long and returns a pointer to the first element. Hence the answer is: No, there is nothing wrong with storing that pointer in your y.

The memory leak will probably result from the fact that you forgot to free that space again. Somewhere in your program you should have a statement like

delete[] y;



免费存储。


to free that storage.


这篇关于VC6中的长指针初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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