Jump to content
  • Advertisement


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


Is this safe??

This topic is 5619 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, I''m currently working on memory management and I come up with a handle-based system. To avoid internal fragmemtation, I rearrange the memoryblocks after every "freeing". Please look at the code and tell me if it''s safe enough or fast enough to use for projects. Other kinds of feedbacks are also welcome

void Alloc::Rearrange(){

	poolIndex = 0;
	Alloc *ptr = head;

	while (ptr != NULL){

		if (ptr->chunkIndex != poolIndex){

			memmove(memoryPool + poolIndex, memoryPool + ptr->chunkIndex, ptr->chunkSize);
			ptr->chunkIndex = poolIndex; poolIndex += ptr->chunkSize;

			poolIndex += ptr->chunkSize;

		ptr = ptr->next;

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
It is generally not very fast moving objects around in memory. It is faster just to allocate a list of continuous objects of the same type, and instead of deleting objects when freed, you throw them onto a list of free objects, and fetch new objects from that list instead of creating new ones. This method has several advantages: You decrease the time spent creating and deleting objects (new/delete), and the internal fragmentation will always decrease as more objects are fetched from the free-list. Of course it is possible to sort the objects in the free-list, but it is not guaranteed to improve performance or decrease internal fragmentation.

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!