# memory and calldata values are not packed unlike storage While the Solidity compiler packs consecutive small variables into shared storage slots, this optimization does not apply to memory or calldata. In memory, every value occupies a full 32-byte slot regardless of its actual size. In calldata, ABI encoding similarly pads values to 32 bytes. This means struct packing optimizations that reduce storage gas costs have no effect on memory operations or function call encoding. Since [[solidity compiler packs multiple small values into one storage slot but writing requires reading the full slot|storage packing depends on declaration order]], developers sometimes confuse storage-only optimization with general EVM behavior. Because [[evm memory gas costs grow quadratically making large allocations prohibitively expensive]], the 32-byte-per-value memory layout makes large in-memory arrays particularly expensive. --- Relevant Notes: - [[solidity compiler packs multiple small values into one storage slot but writing requires reading the full slot]] — the storage-specific packing this contrasts with - [[evm memory gas costs grow quadratically making large allocations prohibitively expensive]] — memory's lack of packing combined with quadratic costs makes large memory operations expensive - [[memory-to-memory assignment in solidity creates references not copies enabling aliasing bugs when both variables modify the same data]] — memory reference semantics operate at the pointer level regardless of the unpacked 32-byte-per-value layout Topics: - [[evm-internals]]