简体   繁体   English

在共享内存提升中复制char *

[英]copy char* in shared memory boost

I want to know if I can write in a file (shared memory with boost) a char*. 我想知道我是否可以在文件(带有Boost的共享内存)中写一个char *。 I have create a Template, and works fine with "int" and "string", but with char*, I can access to them in memory, when I am executing the program, but the data is not stored in the file afterwards as happens with ints and strings. 我已经创建了一个模板,并且可以与“ int”和“ string”一起正常工作,但是使用char *时,我可以在执行程序时在内存中访问它们,但是随后数据不会存储在文件中与整数和字符串。

The representative piece of the code would be: (T would be char*) 该代码的代表性部分为:(T为char *)

//DECLARATIONS
MyMap *mymap;
managed_mapped_file seg = managed_mapped_file(open_or_create, tableName, tablesize);
mymap = seg->find_or_construct<MyMap>("MyMap")      //object name
            (std::less<T>() //first  constructor parameter
            ,*alloc_inst);    //second constructor parameter

//THE METHOD TO ADD THE ENTRIES
template<class T>
void ShareDB<T>::add_ref_info_to_db (const T &Symbol_Index , const std::string &a_info){

MyMap::iterator res =  mymap->find(Symbol_Index);

mymap->insert(std::pair<const T, shared_string>(Symbol_Index, localSymbol));

so I call to the Template like that: 所以我这样调用模板:

ShareDB <char *> ex;
ex.openDB(dataBaseName,"TestMutex", 196608, true);
ex.add_ref_info_to_db (a,ex.RefInfoRecord);

Maybe it is just that I can not write pointers...I am not sure... 也许只是我不能写指针...我不确定...

Thanks in advance 提前致谢

除了template<class T>考虑template<typename T> ... ...但是我将简单地使用std::string除非您必须特别支持char *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM