How to manage large buffer in C++?-Collection of common programming errors
When dealing with large amounts of memory, you have to look at two things, lifecycle, how often you create and recreate this buffer. As memory gets fragmented, there can come a time when you try to allocate a buffer of say, 512MB, and you can’t, because your allocator cannot find 512MB of contiguous address space. This is why @onebyone’s idea of using vectors is sometimes better. If you can reduce your footprint to byte-sized (not literally) chunks, you gain flexibility in how you manage your memory.
That said, I would almost NEVER recommend keeping a large static buffer around. It’s asking for trouble.