问题描述
它说应该避免动态分配内存,因为它会将内存分成小块并分配内存就效率而言,这是一个成本高昂的过程。那么什么是最好的解决方案
处理我们需要在运行时分配内存的情况。
问候
Mayank Jain(Nawal )
9818390836
。使用新的
使用动态分配内存。使用新的
如何解决我的新问题。你是想用新的
代替malloc分配内存吗?
问候
Mayank Jain(Nawal)
共*************** @ gmail.com
9818390836
Hi,
Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
Regards
Mayank Jain(Nawal)
co***************@gmail.com
9818390836
using dynamic allocation of memory. use new
using dynamic allocation of memory. use new
How new is going to solve my problem. Are you trying to say use new
instead of malloc for allocating memory?
Regards
Mayank Jain(Nawal)
co***************@gmail.com
9818390836
It depends on the situation, there is no perfect solution that will work
in all situations. I think that the advice is rather that one should
prefer automatic storage over dynamic when possible. However, one should
be aware that using automatic storage is not possible in all cases, in
fact most non-trivial applications will make use of dynamic memory,
either directly or indirectly via containers.
For some applications were objects of a certain kind needs to be
allocated and deallocated frequently a pool-allocator might increase the
performance and the effects of fragmentations is lessened.
--
Erik Wikstr?m
这篇关于解决办法是什么..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!