Question about memory allocation. 
Author Message
 Question about memory allocation.

    When I program my ATL components, I usually use
CoTaskMemAlloc/CoTaskMemRealloc/CoTaskMemFree to allocate space dynamically.
Now I know that ultimately, this will allocate space off the heap, as will
the new operator.  My question is, if I am only going to use this space
within the context of the current function (and the function calls below
it), is the COM heap allocator worth using in this situation, or should I
just use new instead?  I would assume it takes ^slightly^ longer to use
CoTaskMemAlloc, but obviously, not measurable.

    Also, one other concern.  I don't remember where or when I heard this,
but I recall hearing that using the new operator required the CRT to be
linked into the project.  Is there any validity to this?

    Thank you in advance.

--
                         - Nicholas Paldino



Tue, 09 Jul 2002 03:00:00 GMT  
 Question about memory allocation.
It depends. If you're allocating C++ objects, you definitely prefer new
(for it calls the constructor). Actualy, according to some experiments
I did for a different reason, the setback is less that 0.1 % - nothing to
worry about... Well, I used malloc instead of new, but it's all the same,
new is slower than malloc (because it calls it internally) so the difference
will be even smaller.

You can use new and malloc without pulling in the CRT. ATL implements
them in lieu of the C RTL. That's about everything you can use from
the C RTL though...

--
===============================
Alexander Nickolov
Microsoft MVP [VC], MCSD

===============================

Quote:

>    When I program my ATL components, I usually use
>CoTaskMemAlloc/CoTaskMemRealloc/CoTaskMemFree to allocate space
dynamically.
>Now I know that ultimately, this will allocate space off the heap, as will
>the new operator.  My question is, if I am only going to use this space
>within the context of the current function (and the function calls below
>it), is the COM heap allocator worth using in this situation, or should I
>just use new instead?  I would assume it takes ^slightly^ longer to use
>CoTaskMemAlloc, but obviously, not measurable.

>    Also, one other concern.  I don't remember where or when I heard this,
>but I recall hearing that using the new operator required the CRT to be
>linked into the project.  Is there any validity to this?

>    Thank you in advance.

>--
>                         - Nicholas Paldino




Tue, 09 Jul 2002 03:00:00 GMT  
 Question about memory allocation.
Alexander,

    Excellent, thank you.  I am not creating C++ objects, just strings and
the sort (not the string class, I mean arrays of WCHAR and CHAR, and
structures).  So I guess for things on the stack, malloc is the way to go.
I just get {*filter*}about performance, it will be the death of me haha

    Thanks again.

--
                         - Nicholas Paldino



Fri, 12 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. question about memory allocation

2. General Question about memory allocation

3. Question about memory allocation

4. Question regarding memory allocation/deallocation

5. few questions about memory allocation

6. Questions on memory allocation and gets()

7. ## question on memory allocation for char strings ##

8. Question on memory allocation

9. question about memory allocation

10. Novice question about memory allocation

11. Tree memory allocation, pool memory allocation

12. URGENT Memory allocation question

 

 
Powered by phpBB® Forum Software