Hasty Briefsbeta

Bilingual

Growing Buffers to Avoid Copying Data

a year ago
  • #memory-management
  • #performance
  • #C++
  • Johnny’s Software Lab LLC specializes in software performance optimization.
  • Avoiding data copying is crucial for performance, especially in C++ and operating system contexts.
  • C++ lacks a built-in realloc function, complicating buffer resizing without copying.
  • A proposed resize_buffer function could help avoid unnecessary data copying in C++.
  • Linux uses mmap and mremap for memory allocation and resizing, requiring careful address management.
  • Windows lacks mremap but can use VirtualAlloc for similar purposes, though with more manual management.
  • jemalloc offers xallocx for buffer resizing, a feature not present in standard C libraries.
  • Experiments show significant performance gains when avoiding data copying during buffer resizing.
  • Potential issues include system-specific behaviors, silent failures, and virtual memory fragmentation.
  • Despite challenges, avoiding data copying is beneficial for performance in certain scenarios.