Ptr vs ptr on heap
What´s the difference in using pointers on the heap and "ordinary" pointers. I understand that the memory allocated on heap is still there after the function ends, although what´s the use of keeping it then?
http://www.shakazed.tk
There is a lot more memory available in the heap so for large objects, that''s where you should allocate them from. Also, any pointer to the heap (one that uses "new") should also be deleted with "delete" when the function ends.
tj963
tj963
tj963
I think you''re both confused.
There''s no difference between how a variable acts if it was allocated by you (from the heap) or if it''s function-local (on the stack).
If you allocate something using new, free it using delete. If you allocate something using malloc of calloc, use free.
No more thought is required.
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
There''s no difference between how a variable acts if it was allocated by you (from the heap) or if it''s function-local (on the stack).
If you allocate something using new, free it using delete. If you allocate something using malloc of calloc, use free.
No more thought is required.
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement