int* p = (int*)malloc(sizeof(int)*5);
int* p = (int*)malloc(sizeof(int)*5); Maybe p is 0x0004, but p+1 is not always 0x0008 in physical memory. |
I heard _aligned_malloc allocate in memory without memory fragmentation. but malloc can make a memory fragmentation. because actually malloc does not always allocate memory in physical memory in order. |
I am implementing doubly-linked-list like STL list class. and most container use allocator class. so I was finding how to use allocator and custom allocator. |
someone uses new.. someone uses malloc, someone uses _aligned_malloc.. and so on.. so I just needed to know about memory allocation functions and which is more effective. |
new
(and new[]
) allocate memory and call the constructor. The memory must be deallocated with delete
or delete[]
.malloc()
just returns a block of memory. It is uninitialized and must be dellocated with free()
The documentation usually doesn't state this, but the memory is suitably aligned to store any data type.calloc()
is like malloc()
, but the parameters are different and the returned memory is zero-initialized._aligned_malloc()
returns a block allocated on the requested boundary. It must be freed with _aligned_free()
As an aside, this is C++; can I interest you in not using C code such as malloc, and also not using new? How about using safer, modern C++ to handle your memory? |