DataRecord used a fixed float[129600000] consuming 5GB disk even when collecting only a few hundred data points. Replaced with shm_vector_f that grows on demand via push_back. Removes the need for rm -rf on process exit — vector destructor frees memory back to the segment. Also drops now-unnecessary task_data_size member.
42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
#pragma once
|
||
/**
|
||
* @file TaskData.h
|
||
* @brief task进程,缓存数据(动态vector,按需分配)
|
||
* @author your name (you@domain.com)
|
||
* @version 0.2
|
||
* @date 2024-02-27
|
||
*
|
||
* Copyright: Baosight Co. Ltd.
|
||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||
*/
|
||
#include <mix_cc/shm.h>
|
||
namespace TaskShm {
|
||
namespace SHM = mix_cc::shm;
|
||
namespace bipc = mix_cc::shm::bip;
|
||
|
||
const static std::string dir_path = "/users/dsc/shm";
|
||
const static std::string shm_file = "TaskData"; ///<映射文件名
|
||
const double data_size = 10; ///< 数据大小 MB(按需动态)
|
||
|
||
static bipc::managed_mapped_file
|
||
obj_mapped_file(bipc::open_or_create,
|
||
(dir_path + "/" + shm_file + "_boost.mmap").c_str(),
|
||
mix_cc::data_size::MB(data_size));
|
||
|
||
typedef bipc::managed_mapped_file::segment_manager segment_manager_t;
|
||
typedef bipc::node_allocator<float, segment_manager_t> vec_allocator_f;
|
||
typedef boost::container::vector<float, vec_allocator_f> shm_vector_f;
|
||
|
||
struct TaskRecord {
|
||
shm_vector_f data_record;
|
||
TaskRecord(const bipc::node_allocator<void, segment_manager_t> &alloc)
|
||
: data_record(alloc) {}
|
||
};
|
||
|
||
/*单例 map 记录task数据项*/
|
||
const static bipc::offset_ptr<SHM::Map<int, TaskRecord>> TaskRecordPtr =
|
||
SHM::MapBuilder<int, TaskRecord>::find_or_construct(&obj_mapped_file,
|
||
shm_file);
|
||
|
||
} // namespace TaskShm
|