如何防止Boost.进程间使用wchar
How do I prevent Boost.Interprocess from using wchar?
我正试图交叉编译一些Boost进程间代码到一个没有实现wcslen和wmemset等wchar函数的环境。
下面是我的代码:
#define BOOST_NO_CWCHAR
#define BOOST_NO_CWCTYPE
#define BOOST_NO_CTYPE_FUNCTIONS
#define BOOST_NO_INTRINSIC_WCHAR_T
#define BOOST_NO_STD_WSTREAMBUF
#define BOOST_NO_STD_WSTRING
#define BOOST_NO_CHAR32_T
#define BOOST_NO_CHAR16_T
#define BOOST_NO_CXX11_CHAR16_T
#define BOOST_NO_CXX11_CHAR32_T
#define BOOST_NO_UNICODE_LITERALS
#define BOOST_DATE_TIME_NO_LIB
#define BOOST_ALL_NO_LIB
//#define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED
//#define BOOST_INTERPROCESS_POSIX_TIMEOUTS
//#define BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
#define BOOST_HAS_GETTIMEOFDAY
#define CGAL_HAS_NO_THREADS -U__GNUG__
#define BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY
#define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
#include <boost/interprocess/managed_external_buffer.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/list.hpp>
#include <cstring>
#include <boost/aligned_storage.hpp>
using namespace boost::interprocess;
//Alias an integer node allocator type
//This allocator will allocate memory inside the static buffer
typedef allocator<int, wmanaged_external_buffer::segment_manager>
allocator_t;
//Alias a STL compatible list to be constructed in the static buffer
typedef list<int, allocator_t> MyBufferList;
void processWork(char *data, int size)
{
const int localSize = 65536;
static boost::aligned_storage<localSize>::type static_buffer2;
std::memcpy(&static_buffer2, data, localSize);
wmanaged_external_buffer objects_in_static_memory2
(open_only, &static_buffer2, localSize);
//Check that "MyList" has been duplicated in the second buffer
MyBufferList *list = objects_in_static_memory2.find<MyBufferList>(L"MyList").first;
std::cout << list->front();
**objects_in_static_memory2.destroy<MyBufferList>(L"MyList");**
}
int main()
{
std::cout << "Starting";
//Create the static memory who will store all objects
const int memsize = 65536;
static boost::aligned_storage<memsize>::type static_buffer;
//This managed memory will construct objects associated with
//a wide string in the static buffer
wmanaged_external_buffer objects_in_static_memory
(create_only, &static_buffer, memsize);
//We optimize resources to create 100 named objects in the static buffer
objects_in_static_memory.reserve_named_objects(100);
//The list must be initialized with the allocator
//All objects created with objects_in_static_memory will
//be stored in the static_buffer!
MyBufferList *list = objects_in_static_memory.construct<MyBufferList>(L"MyList")
(objects_in_static_memory.get_segment_manager());
list->push_back(624);
processWork((char*)static_buffer.address(), memsize);
objects_in_static_memory.destroy<MyBufferList>(L"MyList");
return 0;
}
包含L"MyList"的调用会在boost/interprocess/segment_manager.cpp中触发一个调用:
index_it it = index.find(key_type (name, std::char_traits<CharT>::length(name)));
它试图调用libcxx/string中的wcslen,这是我想避免的。
我尝试从缓冲区名称中删除'L',但随后它抱怨参数不是wchar。任何关于如何删除这个wchar依赖的指导都非常感谢-不幸的是,我设置的宏似乎没有做到这一点。
我正在使用最新的Boost头(不是我的系统上的)
马科斯wmanaged_external_buffer
是basic_managed_external_buffer<wchar_t>
的类型定义,就像std::wstring
是std::basic_string<wchar_t>
的类型定义一样。
您应该使用managed_external_buffer
(或直接使用basic_managed_external_buffer<char>
)。
相关文章:
- boost::进程间消息队列引发错误
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 是否可以通过C++扩展强制多个python进程共享同一内存
- IPC使用多个管道和分支进程来运行Python程序
- 异常属于C++中的线程还是进程
- WMI检测进程创建事件-c++
- MacOS通过在莫哈韦"wchar.h"下破碎的自制啤酒发出叮当声
- c++多进程编写一个唯一的文件
- 如何在C++中将函数发送到另一个进程
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 终止 QProcess 不会终止子进程
- 将返回值从 exe 传递到 bat,并将其传递给 C# 中的进程
- COM :是否可以查看是否存在对我的某个 COM 对象的进程外引用?我可以释放它吗?
- Windows 进程间同步类似事件?
- 在挂钩启动新线程时解除挂钩进程
- pclose() 不会给我进程退出代码
- 运行代码时,c++ 会终止进程
- 可以读入进程内存的最大块大小是多少?
- 枚举进程模块在有效句柄上返回无效句柄
- 如何防止Boost.进程间使用wchar