Skip to main content
GameDev.net gamedev.net
🔒 Locked

Heap

Started by wah_on_2 Nov 29, 2001 at 6:49 AM 2 replies 400+ views
Original Post
wah_on_2
wah_on_2
I have a question about C++. int *num; num = new int[200000]; i know i am using heap to store the integers. I want to know how much memory size provided in using heap? Will i use up all the heap memory? which one is better of the heap memory or reallocation? thx! ^^
Spiral
Spiral
if you're using MSVC then new will return a NULL pointer if there was a problem with allocating the memory. Unless you have a very old computer allocating 200 thousand integers (400kb of memory) should not cause a problem.

Edited by - Spiral on November 29, 2001 9:28:38 AM
--------------------Go Stick Your Head In A Pig
wah_on_2
wah_on_2
So, should i use the heap memory anytime? Will heap memory has size limition?

Also, if i create a variable using heap memory in a class, is it mean the variable is gobal variable?

Thanks.
Fruny
Fruny
quote:
Original post by wah_on_2
So, should i use the heap memory anytime? Will heap memory has size limition?

Also, if i create a variable using heap memory in a class, is it mean the variable is gobal variable?




The limitation in size is how much memory you''ve got in your machine, minus what''s already used by other applications. Fire up the task manager to have a look at that.

Allocating memory on the heap does not change the scope of the pointer variable you use to access it. Remember to free it at some point though, or you''ll get a memory leak.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.