I’m trying to feed an array with fscanf() while looping through a file containing a list of integers, n integers long. It seems that I need to use malloc and/or potentially realloc. I’ve heard that the malloc command takes a noticeable amount of execution time and that it’s best to over-allocate. Would someone mind helping me out with understanding the building blocks of accomplishing this end?
Disclaimer: I’m new to C.
No, what you’ve heard is misleading (at least to me).
mallocis a just a function, and usually a fast one.mallocIt’s unrealistic to think you can easily beat
mallocat this game. I am sorry if this doesn’t answer your question (which was pretty general) but you have to realize there is no (spoon) optimization you can easily implement.