Solved

Dynamic memory allocation

Posted on 1998-09-23
9
339 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Event ID 10010 3 69
Example of WebAPI 7 33
How to update List item Managed Metadata Column with JSOM 2 208
Is COM supported from Apache 1 65
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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