Click here to Skip to main content
15,038,345 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
<pre>//allloc the memory
int * lastBuffer = new int[1<<m_exp];

//free the memroy by std::free()
std::free(lastBuffer );


the free method is OK? if not ,what's the problem?

Or more info?
Posted

NEVER EVER mismatch the "alloaction pairs"

new <-> delete
alloc <-> free

Make a poster and hang it above your bed ;-)
   
Comments
nv3 12-Jul-13 3:03am
   
In this case it's even "delete []". My 5.
H.Brydon 12-Jul-13 15:35pm
   
Right, you almost said it but didn't:

new < - > delete
new[] < - > delete []
alloc() < - > free()
KarstenK 15-Jul-13 2:14am
   
"You got it" ;-)
If you use malloc to allocate memory, use free to deallocate it.
If you use new to allocate memory, use delete to deallocate it.
Never mix them together.

Read what the man himself has to say - http://www.stroustrup.com/bs_faq2.html#malloc[^]
   
Comments
H.Brydon 12-Jul-13 15:36pm
   
As per solution #1, new goes with delete, new[] goes with delete[]...
+5 anyhow...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900