I have networking application which sends data, it consists of executable and multiple DLLs which also add some data to Buffer class. class Client contains Buffer as member object buffer, when data need to be sent it first calls Client::pack for itself and then for DLLs(shown as DLL::pack in code), I always pass buffer as reference. When I call DLL::pack with this->buffer argument it works without a problem, but once I use only buffer which was passed by reference from Client::send function so I assume it's same as this->buffer, the DLL somehow creates new copy of buffer which is independent of what I passed from Client::pack so anything I do DLL doesn't show in Client, the DLL actually makes new buffer initialized to default values so it's not even a copy of what I passed in the function and to make it even weirder the object which "cloned" doesn't even get automatically destroyed after DLL::pack function ends. When I print number of bytes in buffer on beginning and end of DLL::pack function, I would except something like: "0 4 0 4 0 4 0 4" but I get this instead: "0 4 4 8 8 12 12 16" so it just stays in memory. Does anyone know why would this "cloning" happen?
//EXE code
void Client::send()
{
this->pack(this->buffer);
}
void Client::pack(Buffer& buffer)
{
DLL::pack(buffer); //DLL creates own copy of buffer
//DLL::pack(this->buffer) works when uncommented
}
//DLL code
void DLL:pack(Buffer& buffer)
{
//fill buffer with data
}

