• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Dynamic memory allocation

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
Zainal062797
Asked:
Zainal062797
  • 5
  • 2
  • 2
1 Solution
 
BonevCommented:
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
 
Zainal062797Author Commented:
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
 
nietodCommented:
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: 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.

 
nietodCommented:
Bonev chose not to answer, so you don't have the option to grade.  Perhaps he will now?
0
 
BonevCommented:
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
 
BonevCommented:
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
 
BonevCommented:
nietod, thanks
0
 
Zainal062797Author Commented:
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
 
BonevCommented:
It should be there.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now