Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Leadorn

Memory allocation

This topic is 6017 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

Hail I have some questions about memory. If i allocate *ptaData = new int[15]; do i have a array with adresses to 16 different int locations or do i have an pointer to an array on the same memoryplace? Does it look lika this? *ptaData Pointers adress data [0] an andress to int any where [1] an andress to int any where [2] an andress to int any where Or *ptaData Pointer adress an andress to int array any were, but the array will be on the same place after an other. |----------------- | | | | |_______________________ |45 int data | |46 int data | |47 int data | |48 int data | |49 int data | |50 int data | |... in this case i goto 45 then if I want to access the next item num 46 i use ptrData[2] or ptrdata+1 (+sizeof ptrData). One last question. I want to dynamic allocate int *ipData[10](not dynamic); But if i use *ptrData = new int[10]; I allocate 10 int locations. I only want the first pointer array (*ipData) not what it is pointing to. I want the address to be NULL only a var...... *ipData [0] address NULL [1] address NULL

Share this post


Link to post
Share on other sites
Advertisement
But if i want an array where i can store many different adresses to ex dynamic allocated memory places.

Mkay i get it...
But please answer this...

if i use int *ipData[10] i get a array that i can store adresses in. But if i use *ipData = new int[10]; i get a array with allready allocated adresses to 10 int....or am I wrong?.

But I want a dynamic arraysize that i can reallocate, i dont want the 10 mapped int memory. just the parray.

Share this post


Link to post
Share on other sites
If i want to delete this adresses ive put in the int **pointer_array = new int *[10]; how do i do that?

delete [] *pointer_array;?=??????

Share this post


Link to post
Share on other sites
This works??? i thinkso. But is there a better way?

for(int ab=0;ab <= 9;ab++)
{
delete pointer_array[ab];
}

Share this post


Link to post
Share on other sites
No, there is no other way with arrays of pointers [nystagmus is crouching down waitning for the blows to come]. You have to delete each single pointer. Watch out though so that you don''t accidentally try to delete a pointer that hasn''t been allocated.

Share this post


Link to post
Share on other sites
quote:
Original post by Leadorn
But is there a better way?

Of course. It looks like:


  
std::vector<boost::shared_ptr<int> > v;


Check out the Boost website for their smart pointers.

Share this post


Link to post
Share on other sites
Isent the adress NULL an adress? Should I repoint the pointerarray to NULL all of them?

Dosent any program store data on adress NULL (0)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you try to read or write to a pointer which points at NULL you will cause an invalid page fault

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!