Find Related products on Amazon

Shop on Amazon

Growing Buffers to Avoid Copying Data

Published on: 2025-05-09 15:16:21

We at Johnny’s Software Lab LLC are experts in performance. If performance is in any way concern in your software project, feel free to contact us. Copying data can be expensive in some cases, especially since it it doesn’t change the data, it’s just moves it. Therefore we, engineers interested in performance, want to avoid copying data as much as possible. We already talked about avoiding data copying in C++ earlier. In that post, we talked about what mechanism C++ has to offer when it comes to avoiding or minimizing copying. In this post, we focus more on what the operating system can give us to avoid data copying. A small introduction Among memory allocation functions in C library, one function is particular: realloc . This function allows us to grow or shrink a buffer allocated with malloc or calloc : if realloc can do it in place, it will avoid copying data. If not, then it will allocate a new buffer, copy the data there, and free the old buffer. If you are using C, this is a ... Read full article.