Solved

Dynamic memory allocation

Posted on 1998-09-23
9
333 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

15 Experts available now in Live!

Get 1:1 Help Now