Solved

Dynamic memory allocation

Posted on 1998-09-23
9
336 Views
Last Modified: 2013-12-03
Is there an advantage to use GlobalAllocate() and other Windows memory allocation functions as opposed to using C++'s "new" or C's malloc()? Does GlobalAllocate(), for example, work better with virtual memory? Note: I program in Win32 environment.

Thank you.
0
Comment
Question by:Zainal062797
  • 5
  • 2
  • 2
9 Comments
 
LVL 1

Expert Comment

by:Bonev
ID: 1414750
The difference is that the C/C++ functions add an abstract layer that allows portability. By my opinion it is better to use them because they manage their own heap and it is easy to track down various memory problems like leaks and overwrites. In their implementation they use the Windows API functions for memory management adding a small overhead that reduces the speed a little bit, but certainly give you the advantage of better memory control.
0
 

Author Comment

by:Zainal062797
ID: 1414751
Thanks...
Where is the grading form?? It used to be at the end of the answer. But the last couple of times, I had to ask for it.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1414752
It is best to use the C++ allocation procedures (except when some window-speciifc features are need, like the DDE share)  This will keep window's heap simpler (with less block and less gaps).  C++ will allocate a few large blocks out of window's heap and create its own heaps in these blocks.  If you allocate lots of objects, it is more efficient to allocate them in C++'s heaps rather than cluter up window's heap.  (It is more efficient, because your program is working in a smaller heap because it doesn't have to deal with blocks allocated from other programs and at the same time when windows needs to modify its heap, its heap is simpler because it has only the 1 or 2 heap objects from your program, rather than every block from your program.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414753
Bonev chose not to answer, so you don't have the option to grade.  Perhaps he will now?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Bonev
ID: 1414754
I have posted that as a comment. In this way I give an opportunity to other experts to give their opinion. If you are happy with my comment I can post it as an answer. If not, you can wait for more comments in the discussion.

0
 
LVL 1

Accepted Solution

by:
Bonev earned 50 total points
ID: 1414755
As requested:

The difference is that the C/C++ functions add an abstract layer that allows portability. By my opinion it is better to use them because they manage their own heap and it is easy to track down various memory problems like leaks and overwrites. In their implementation they use the Windows API functions for memory management adding a small overhead that reduces the speed a little bit, but certainly give you the advantage of better memory control.

0
 
LVL 1

Expert Comment

by:Bonev
ID: 1414756
nietod, thanks
0
 

Author Comment

by:Zainal062797
ID: 1414757
Thanks...
Where is the grading form?? It used to be at the end of the answer. But the last couple of times, I had to ask for it.

0
 
LVL 1

Expert Comment

by:Bonev
ID: 1414758
It should be there.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now