473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Advanced Allocation/Deallocation in Memory

Hi there,

I'm coming to you nice people as a desperate resort with time working against me, anyway:

I have implemented an algorithm that basically generates a very large tree of nodes, where each node just contains 4 pointers to other nodes.

Now this generation of a tree occurs many times in the programs operation, and with the creation of new Node objects I gradually run out of memory. Obviously I need to deallocate them between each tree generation; so infact I decided that all the objects would be stored in an array (inter-connected via pointers to create the tree) so I could simply for-loop backwards from the last node created in the array, performing delete Node.

Unfortunately, the "last node created" in the first tree is indexed at 1251260, and they only get bigger. My memory consumption problem is now gone, but I'm finding the process of deleting (for loop + delete node +set node to null) is taking a very long time. Too long really.

I'm suprised by this, because I always thought memory allocation was more expensive than deallocation, yet it manages to allocate all the nodes in mere seconds, while taking a couple of minutes to deallocate them all. Is there some extremly quick way for me to delete the whole array of nodes much quicker? Is there something obvious I don't know that I should?

Thank you in advance,
Matt Kent
Aug 8 '09 #1
3 2596
JosAH
11,448 Expert 8TB
Why don't you allocate entire chunks/arrays of tree nodes and marshall them to your tree code one by one? If the chunk is entirely used, allocate a new one again.

When you want to get rid of your tree you just have to deallocate the chunks used in the step above. If those chunks are quite big (say 1024 nodes or so) the freeing process won't take much time.

kind regards,

Jos
Aug 8 '09 #2
A logical suggestion, and likely the best. Thank you.
Aug 8 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
Are you using Windows?

If so, use a private process heap and not the CRT heap. When you are done, just delete the entire heap. No need for cleanup at all.
Aug 8 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Chris S. | last post by:
Is it possible to determine how much memory is allocated by an arbitrary Python object? There doesn't seem to be anything in the docs about this, but considering that Python manages memory...
1
by: Spur | last post by:
Hi all, I implemented a memory allocation/deallocation class that logs all new/delete calls (overloaded) and remembers for each allocated block where it was allocated from (using a macro that...
5
by: Lionel | last post by:
Hi all, Just wondering exactly how memory is allocated using the new operator? More specifically I am interested in how the memory is calculated for globable variables? I recently stumbled into...
9
by: Andrew Au | last post by:
Dear all, I am trying to write a piece of software that use Object Oriented design and implement it with C, I did the following == In Object.h == typedef struct ObjectStructure* Object; ...
10
by: jklimek | last post by:
I'm currently a Delphi developer (my day job) but at my company we only write custom web application/database stuff, so we never really get into anything advanced. However, I know enough about...
12
by: whitehatmiracle | last post by:
Hi all Im not quite sure how to use the new and delete for a whole array dynamically. Actually i want that, a user inputs a char in a single char array. Everytime he inputs a char he creates a...
3
by: mackenzie | last post by:
I was wondering why it is "ill-formed if an allocation function is declared in a namespace"? I have done some searching on the web and can not find a reason why; I have stumbled across a few other...
158
by: jacob navia | last post by:
1: It is not possible to check EVERY malloc result within complex software. 2: The reasonable solution (use a garbage collector) is not possible for whatever reasons. 3: A solution like the...
9
by: danil52 | last post by:
I have dynamic memory allocation in my constructor and deallocation in my destructor. However if there is exception being thrown in constructor, the destructor does not get called and memory leaks...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.