Click here to Skip to main content
15,077,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1)If I create malloc() and to increase size i use realloc()
2)If i create malloc() , use free() to remove memory and again malloc() to increase the size

Did there is disadvantage if I use 2 method instead of 1 also did there any difference between 1 and 2 method

What I have tried:

no idea if there can be any difference o disadvantage
Posted
Updated 17-Nov-17 22:30pm
Comments
Richard MacCutchan 18-Nov-17 4:10am
   
Run some timing tests to see.

1 solution

The advantage of realloc is that havent to write and run the copy function and should be faster sometimes, because malloc often uses a greater chunk which got used in the realloc.

In programs it is best use to copy as little memory because there is no advantage in it. It better to work carefully with the pointers.

As Richard wrote: write some big loops to test it out.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900