+ 1
What happen when use dynamic memory in different programming language?
6 ответов
+ 1
but in c there are problems from heap such as fragmantation so what we do to overcome this?
+ 1
Good question! You must be doing some embedded programming if you're worried about this.
What you are looking for is a memory pool. The details are more than I can get into here but the basic idea is that you allocate a block of memory (usually the size of the heap so any other allocations fail) and then assign blocks of memory to the pool. Usually implementations include FIFO block allocation or a lifetime allocation with semaphore access.
+ 1
Here's a few (pulled from searching "c memory pool"):
http://stackoverflow.com/questions/11749386/implement-own-memory-pool
https://www.codeproject.com/articles/27487/why-to-use-memory-pool-and-how-to-implement-it
https://codereview.stackexchange.com/questions/48919/simple-memory-pool-using-no-extra-memory
+ 1
Did this answer your question? Use the check mark next to my response that marks it as the answer. Thank you.
0
In all languages dynamic memory is allocated to the heap.
In C any allocated memory must be manually deallocated.
In C++ well designed code should deallocate memory when allocated memory falls out-of-scope (see RAII and smart pointers).
In C# and Java nearly everything is allocated to the heap and the virtual machine's garbage collector deallocates unused heap space in blocks.
0
can you please give me link to do that?
link ? code?
any help