Boost >= 1.87 throws bad_alloc when allocating memory for a 64-byte aligned data structure using managed_shared_memory, even though there is sufficient free memory

Đang mở
#1,041 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
operating-systems

Hướng nghiên cứu

Tái hiện ví dụ managed_shared_memory được cung cấp với MyClass<32768> và kiểm tra allocate_aligned trong include/boost/interprocess/mem_algo/detail/mem_algo_common.hpp, đồng thời so sánh hành vi giữa các phiên bản Boost được đề cập. Theo dõi cách real_size được tính toán tương quan với get_free_memory; công việc được hoàn tất khi hồi quy được giải thích và hành vi cấp phát có căn chỉnh được bao phủ bởi một bài kiểm thử hồi quy phù hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Hi there, I haven't tested this with Boost 1.86, jumped straight from 1.85 to 1.87. The code snippet below works well in Boost 1.85, but when using 1.87 or 1.88, I noticed it fails and throw bad_alloc. Some changes related to memory_algorithm seem to break it. While debugging, I found that the real_size calculated in allocate_aligned is larger than the currently available free memory. I'm also wondering if I'm using it incorrectly. Please advise — thanks!

#include <iostream>
#include "boost/interprocess/interprocess_fwd.hpp"
#include "boost/interprocess/managed_shared_memory.hpp"
#include "boost/interprocess/shared_memory_object.hpp"

template <size_t N)>
class MyClass {
 public:
  static_assert((N & (N - 1)) == 0, "size must be power of 2");

private:
  alignas(64) std::array<uint8_t, N> data_;
};

namespace bip = boost::interprocess;



int main() {
  constexpr auto kName = "TestShm";
  bip::shared_memory_object::remove(kName);
  try {
    auto shm = bip::managed_shared_memory(bip::open_or_create, kName,
                                          65536);
    auto free_mem = shm.get_free_memory();
    std::cout << "Free mem: " << free_mem << std::endl;
    using Data = MyClass<32768>;
    [[maybe_unused]] auto data = shm.find_or_construct<Data>("Data")();
  }
  catch (const std::exception& e) {
    std::cout << "Fail, " << e.what() << std::endl;
    bip::shared_memory_object::remove(kName);
    return 1;
  }

  bip::shared_memory_object::remove(kName);
  return 0;
}

Ngôn ngữ chính
HTML
Star
8.6k
Fork
2k
Merge trung bình
9 giờ 35 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của boostorg/boost

Tất cả issue của boostorg/boost

Issue tương tự

Thêm issue về Operating Systems

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.