Jump to content
  • Advertisement

Archived

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

OleKaiwalker

Split Dynamic Memory

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

Hey, If I have allocated some dynamic memory... lets say int *pInt = (int*)malloc(32*sizeof(int)); And want to split it into smaller parts (yup Memory Management ) How can I come across that problem? Should I just free the allocated memory and then allocated it again in two pieces, where the sum of their size matches the size of the first block?? That wouldn''t create any fragmentation? If I try to visualize it I don''t see the fragmentation... Heap when the first block is allocated (A is first block and B something completly else) AAAABBB... Heap when the block is freed ....BBB... Heap when I reallocate in smaller chunks A1A1A2A2BBB... Any fragmentation?

Share this post


Link to post
Share on other sites
Advertisement
I think there is fragmentation since memory management needs control structures that are put in front of the allocated memory. If that''s true for the kind of memory management you use, 2 seperatly allocated pieces eat up more space than one and don''t fit into the gap any more.

Share this post


Link to post
Share on other sites
if you have "ptr" and you want to break it down to "ptr1" and "ptr2"

ptr = new int[100] ;
ptr1 = ptr ;
ptr2 = ptr + 63 ;

that would give you one pointer from element 1 and up and ptr2 would start from 63 being the first element.

Share this post


Link to post
Share on other sites
It is if you want it to be. Memory management isn''t set in stone. If it makes sense, try it.

Most memory managers for games allocate a big heap once, and do their own management within it, generally by just offsetting the base pointer and tracking things.

I like pie.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!