About memory allocation and C ++

And I quote from MSDN http://msdn.microsoft.com/en-us/library/aa366533(VS.85).aspx :

The malloc function has a lack of runtime dependent. The new operator has a compiler drawback dependent and language dependent.

Now the questions are:

a) What do we mean that malloc is runtime dependent? What dynamic memory allocation functions can be independent of runtime? This statement sounds strange.

b) is the new language dependent? Of course it should be right? Are HeapAlloc, LocalAlloc etc. Independent?

c) From a pure performance point of view, are MSVC-supported routines preferred?

Arpan

+3
source share
4 answers

a) In this case, I think they believe the "runtime library" in "run-time". In other words, it depends on the implementation in your C library.

b) Really new is C ++. HeapAlloc etc. Technically applicable in C and C ++.

c) They cannot be used to create C ++ objects, because they will not call constructors, so the point is quite controversial. In C ++ you should use new and delete.

+1
source

malloc new DLL. DLL CRT. , EXE. , . STL.

- /MD. , DLL. , , .

COM, . , , . COM- , COM, CoTaskMemAlloc().

, HeapAlloc() . , HeapCreate(). , .


: VS2012, CRT , ( GetProcessHeap).

+4

a) , malloc C-runtime, .

b) HeapAlloc LocalAlloc - Win32 API. .

c) , , . , . , , , . , - .;)

: LocalAlloc GlobalAlloc . , API Win32.

0

, , . , ++? :

a) , , , , static. , , , , alloca.

b) , ++ new, , free() . .

c) Use C ++ newand delete. You should assume that the main C ++ allocator in the MSVC runtime runs as fast as if it is not identical to C-style system calls. Just remember that newthey deletedo more than allocate and free memory. They are not purely interchangeable with mallocand freeor other C-style distributions.

0
source

Source: https://habr.com/ru/post/1749811/


All Articles