/* Examples of LLFIO use (C) 2018 - 2022 Niall Douglas (2 commits) File Created: Aug 2018 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License in the accompanying file Licence.txt or at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Distributed under the Boost Software License, Version 1.0. (See accompanying file Licence.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include "../include/llfio.hpp" #include #include #include // clang-format off #ifdef _MSC_VER #pragma warning(disable: 4706) // assignment within conditional #endif #if !defined(__SIZE_MAX__) || __SIZE_MAX__ > 999999999999UL void sparse_array() { //! [sparse_array] namespace llfio = LLFIO_V2_NAMESPACE; // Make me a 1 trillion element sparsely allocated integer array! llfio::mapped_file_handle mfh = llfio::mapped_temp_inode().value(); // On an extents based filing system, doesn't actually allocate any physical // storage but does map approximately 4Tb of all bits zero data into memory (void) mfh.truncate(1000000000000ULL * sizeof(int)); // Create a typed view of the one trillion integers llfio::attached one_trillion_int_array(mfh); // Write and read as you see fit, if you exceed physical RAM it'll be paged out one_trillion_int_array[0] = 5; one_trillion_int_array[999999999999ULL] = 6; //! [sparse_array] } #endif int main() { return 0; }