简体   繁体   English

将缓冲区内容复制到另一个缓冲区

[英]copy buffer contents to another buffer

I have the contents of an http request in my buffer. 我的缓冲区中有一个http请求的内容。 I then define another buffer of the same size as the last one. 然后,我定义另一个与上一个缓冲区大小相同的缓冲区。 And i need to copy the contents of the buffer to my new buffer. 而且我需要将缓冲区的内容复制到新缓冲区中。 So the help i need is that how do i get to copy one buffer to another buffer. 因此,我需要的帮助是如何将一个缓冲区复制到另一个缓冲区。

I tried memcpy but it is not working. 我尝试了memcpy但无法正常工作。

void TrivialMediaPlayer::DeliverMediaData(
        int                         streamId,
        bool                        bHasPriority,
        ConstBufferSptr             pMediaData)

What i want is to copy the contents of pMediaData to a new buffer. 我想要的是将pMediaData的内容复制到新缓冲区。

BufferSptr buf1 (new Buffer (pMediaData->Size()) );

i want to copy pMediaData in buf1 . 我想将pMediaData复制到buf1

thanks 谢谢

I am not sure what the exact code you write to copy from one StringSptr from another. 我不确定要编写的确切代码是从一个StringSptr复制到另一个。 But if you wanna 但是如果你想

memcpy( (void*)buf1 , (void*)pMediaData , pMediaData.Size() );

You must make sure that you should defined the "void*" function in the BufferSptr class (seems like a class written by you) to convert your BufferSptr object to a real C pointer which point to the address of internal buffer. 您必须确保在BufferSptr类中定义“ void *”函数(似乎类似于您编写的类),以将BufferSptr对象转换为指向内部缓冲区地址的真实C指针。
Or, use some explicit call: 或者,使用一些显式调用:

memcpy( buf1.data() , pMediaData.data() , pMediaData.Size() );

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

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