Article 66ZK8 What is the Memory Usage of a Small Array in C++?

What is the Memory Usage of a Small Array in C++?

by
hubie
from SoylentNews on (#66ZK8)

fliptop writes:

Techno-optimist and a free-speech advocate Daniel Lemire asks:

In an earlier blog post, I reported that the memory usage of a small byte array in Java (e.g., an array containing 4 bytes) was about 24 bytes. In other words: allocating small blocks of memory has substantial overhead.

What happens in C++?

To find out, I can try to allocate one million 4-byte arrays and look at the total memory usage of the process. Of course, the memory usage of the process will include some overhead unrelated to the 4-byte arrays, but we expect that such overhead will be relatively small.

Results are: GCC 8, Linux x86 - 32 bytes, LLVM 14, Apple aarch64 - 16 bytes. GitHub link to code he used.

Previously: Beyond C++: The promise of Rust, Carbon, and Cppfront

Original Submission

Read more of this story at SoylentNews.

External Content
Source RSS or Atom Feed
Feed Location https://soylentnews.org/index.rss
Feed Title SoylentNews
Feed Link https://soylentnews.org/
Feed Copyright Copyright 2014, SoylentNews
Reply 0 comments