| |

VerySource

 Forgot password?
 Register
Search
View: 837|Reply: 8

How to release the secondary pointer? Ask everyone for help!

[Copy link]

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Korea, Republic of

Post time: 2020-2-23 21:30:01
| Show all posts |Read mode
unsigned char ** pMyArray = new unsigned char * [nMyArrayNum];
Used when releasing
delete [] pMyArray;
The result will be an error.
With loop, delete pMyArray [i]
It doesn't work either.
I ask heroes to help!

Question supplement: Use the following code, there is no problem when compiling and linking, but an error will pop up when running.
if (pMyArray! = NULL)
{
delete [] pMyArray;
pMyArray = NULL;
}
The pointer memory in the array is still useful, so it is not deleted, only the pointer array is deleted.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-5-11 17:00:02
| Show all posts
Where do you apply for space?
Reply

Use magic Report

0

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-5-12 15:15:01
| Show all posts
delete [] pMyArray [i]
Reply

Use magic Report

0

Threads

32

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 Invalid IP Address

Post time: 2020-5-12 16:45:01
| Show all posts
> How to release the secondary pointer?
-------------------------
Delete pMyArray [i] first, then delete pMyArray

> The pointer memory in the array is still useful, so it will not be deleted, only the pointer array.
-------------------------
Then don't delete it, wait until you don't need to delete it again, or don't use the second pole pointer.
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-5-19 19:15:02
| Show all posts
yangkern: Where do you apply for space?

At the time of definition, we applied for space for the array of pointers, and then used the elements of this array as pointers. The address pointed to by the elements has already been applied. Here, we only use pointers to assign values.
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-5-21 02:30:01
| Show all posts
Level by level
Agree withpretendersam
> int ** p = new int * [N];
> for (i = 0; i <N; i ++)
> p [i] = new int [N];
>
> for (i = 0; i <N; i ++)
> delete [] p [i];
> delete [] p;
Reply

Use magic Report

1

Threads

27

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-5-26 19:45:01
| Show all posts
Agree upstairs
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-5-31 13:45:01
| Show all posts
Got it, my question, the array is out of bounds. . . Ugh. . .
thank you all! ! !
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-5-31 17:00:02
| Show all posts
I'm so sorry. . . What a shame. . .
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list