A Resizable C++ Container using Virtual Memory

Blaž Rojc, Matjaž Depolli

2021

Abstract

Thread safety is required for shared data structures in shared-memory parallel approaches, but cannot be done efficiently for standard C++ containers with continuous memory storage, such as std::vector. Dynamically resizing such a container may cause pointer and reference invalidation and therefore cannot be done in parallel environments without exclusive access protection to the container. We present a thread-safe no-copy resizable C++ container class that can be used to store shared data among threads of a program on a shared-memory system. The container relies on the virtual memory controller to handle allocation as needed during execution. A block of memory of almost arbitrary size can be allocated, which is only mapped to physical memory during the first access, providing hardware-level thread blocking. All synchronization costs are already included in the operating system memory management, so using the container in parallel environment incurs no additional costs. As a bonus, references and pointers to elements of the container work as expected even after the container is resized. The implementation is not general however, and relies on the specifics of the operating system and computer architecture. Memory overhead can be high as the allocations are bound to the granularity of the virtual memory system.

Download


Paper Citation


in Harvard Style

Rojc B. and Depolli M. (2021). A Resizable C++ Container using Virtual Memory. In Proceedings of the 16th International Conference on Software Technologies - Volume 1: ICSOFT, ISBN 978-989-758-523-4, pages 481-488. DOI: 10.5220/0010557104810488


in Bibtex Style

@conference{icsoft21,
author={Blaž Rojc and Matjaž Depolli},
title={A Resizable C++ Container using Virtual Memory},
booktitle={Proceedings of the 16th International Conference on Software Technologies - Volume 1: ICSOFT,},
year={2021},
pages={481-488},
publisher={SciTePress},
organization={INSTICC},
doi={10.5220/0010557104810488},
isbn={978-989-758-523-4},
}


in EndNote Style

TY - CONF

JO - Proceedings of the 16th International Conference on Software Technologies - Volume 1: ICSOFT,
TI - A Resizable C++ Container using Virtual Memory
SN - 978-989-758-523-4
AU - Rojc B.
AU - Depolli M.
PY - 2021
SP - 481
EP - 488
DO - 10.5220/0010557104810488