如何在BYTE *上添加或附加额外的字节? [英] How to add or append Extra bytes to BYTE*?

查看:95
本文介绍了如何在BYTE *上添加或附加额外的字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向BYTE *添加或附加多余的字节?

How to add or append Extra bytes to BYTE*?

推荐答案

通过查看注释,您需要动态分配缓冲区的大小:
From looking at your comments, you need to dynamically allocate the size of the buffer:
BYTE *buffer = NULL; //<-- Declare
...
buffer = new BYTE[size]; //<-- Allocate once size is known
memcpy(buffer, data_source, size); //<-- Copy data over from source
...
delete [] buffer; //<-- Deallocate when done with buffer


这个问题不是100%明确的.如果您的意思是这是指向堆的指针,并且需要通过同一指针为数据指针块分配更多的内存,则需要使用realloc.

方法如下: http://www.cplusplus.com/reference/clibrary/cstdlib/realloc/ [ ^ ].

—SA
This question is not 100% clear. If you mean that this is a pointer to heap and you need to allocate more memory for the block of data pointer by the same pointer, you need to use realloc.

Here is how: http://www.cplusplus.com/reference/clibrary/cstdlib/realloc/[^].

—SA


您要在运行时增加BYTE数组的大小,这是您想要实现的目标吗?
不幸的是,这在C/C ++中是不可能直接实现的.相反,您可以做的是这些解决方案之一:
1)使用支持动态容器的STL容器(矢量,列表等).仅当您编写C ++代码时,这才有可能
2)当您需要增加数组的大小时,请创建一个正确大小的新数组,复制前一个数组的所有内容,然后删除前一个数组.
You want to increase the size of your BYTE array at runtime, is that what you want to achieve ?
Unfortunately, this is not directly possible in C/C++. What you could do instead is one of those solutions:
1) Use a STL container (vector, list, ...) which has support for dynamic container. This is only possible if you write C++ code
2) When you need to increase the size of the array, create a new array of the correct size, copy all the contents of the previous array and delete the previous array.


这篇关于如何在BYTE *上添加或附加额外的字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆