• Advertisement
Sign in to follow this  

Quick Question on Pointer Array Allocation

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When you allocate a pointer array (or whatever its called when you do new int[50]), are all of the pointers allocated on the stack in a row? Like is the pointer array just one block in order, or is it scattered? I've done some tests and ran programs and it seems that it is always allocated in a block in order, but I just wanted to make sure that it always happens like this. [c++ if ya couldnt tell...]

Share this post


Link to post
Share on other sites
Advertisement
It's called array allocation. When you do new T[n], n T's are allocated contiguously and a pointer to the first one is returned.

Share this post


Link to post
Share on other sites

Hello,

Sounds a bit messed up. When you use "new" operator you allocate memory from the heap (not from the stack).

I wouldn't call "new int[50]" as a pointer array. It is an array of ints. An array is always a continuous block of memory.

"new int*[50]" would be an array of pointer. In that case, the pointers stored in the array and they are located in continuous block.

I am sorry, maybe I don't understand correctly.

Cheers

Share this post


Link to post
Share on other sites
Oh, yeah, sorry, I meant heap. Thanks though, I didn't know all arrays were continuous blocks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement