Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Using malloc/free in a tight loop
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Mikko Rauhala, post: 4157424"] You know, if you have a very short maximum cap for the length, you could just allocate that and reuse the buffer. (You could also by default reuse the buffer and only reallocate a larger one as it becomes necessary.) That said, the first response was correct in that it's not likely to make much of a difference in this quite simple case. In general though, I would avoid unnecessary repeated allocations and frees in a tight loop. In general, it can indeed. Especially if your processing step here involves allocating space that _isn't_ freed, it can happen in your example too, but probably not to a large extent. (The malloc implementation just needs to be smart enough to reuse the space left by the previous freed buffer, in the common case that it's sufficiently large). [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Using malloc/free in a tight loop
Top