lundi 1 octobre 2018

creating an ::std::string object in shared buffer memory

I am using google protobuf in an embedded application with limited heap memory. I am currently trying to make the application to use dynamic allocation only as a last resort. For this I have some shared buffer on which I create all the proto messages, or most of them. Everything seems to be Ok, expect for the casses where the proto message expects a ::std::string parameter.

The way I understand the ::std::string constructors description, is that it will create a copy of the data I supply. For example this constructor

s = new(sharedBufferAddress) ::std::string(mApn, mApnSize);

where

char                        mApn[APN_MAX_SIZE];
int8_t                      mApnSize;

will create an obect located at the sharedBufferAddress, but the data inside will be copied on a buffer assigned on the heap.

The question is wether there is some way to have the pointer that is returned by the c_str() function to some specified address.

Aucun commentaire:

Enregistrer un commentaire