eis/shm/TaskData.h
Huamonarch e21b2af2a6 Replace fixed 518MB array in TaskData with dynamic shared-memory vector
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.
2026-05-12 17:19:44 +08:00

42 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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