Why do some people use HeapAlloc instead of malloc?
-
I have seen some folks using HeapAlloc instead of malloc, how is that different?
thanks!
-
I have seen some folks using HeapAlloc instead of malloc, how is that different?
thanks!
-
I have seen some folks using HeapAlloc instead of malloc, how is that different?
thanks!
They are effectively the same. However malloc is in the C runtime libraries, so if you use it your application has to link in the C runtime. HeapAlloc is defined in kernel32.dll, so if you want to reduce the code size of your application you can avoid linking to the C runtime and use HeapAlloc to allocate memory. Using HeapAlloc may make your code less portable if that is a concern for you. I hope this helps.
Deus caritas est
-
They are effectively the same. However malloc is in the C runtime libraries, so if you use it your application has to link in the C runtime. HeapAlloc is defined in kernel32.dll, so if you want to reduce the code size of your application you can avoid linking to the C runtime and use HeapAlloc to allocate memory. Using HeapAlloc may make your code less portable if that is a concern for you. I hope this helps.
Deus caritas est
Portability across different OSes or even across different flavours of Windows?
thanks!
-
Portability across different OSes or even across different flavours of Windows?
thanks!
Across different OSs.
Deus caritas est
-
I have seen some folks using HeapAlloc instead of malloc, how is that different?
thanks!
Every process creates a default process heap. This is the heap used by malloc/new/... Aside from using the process heap, malloc/new/... (can) add other optimization features such as lookaside lists, small-block heaps, ... HeapAlloc is the low level way to alloc a block of memory on a heap. Some people will create a number of heaps within a program, each designed to hold a specific type of data or a specific group of data. This can help reduce heap fragmentation and speed up parts of some applications. I use separate heaps for different types of data (e.g. all string buffers in one heap, all blobs in another, ...). I use separate heaps for different groups of data (e.g. all database column data in one heap, all network packets in another, ...). This just touches on the subject. In the end it provides the developer with just another tool.
...cmk Save the whales - collect the whole set