内存池? [英] memory pool?

查看:69
本文介绍了内存池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我正在用相机拍摄一张小块的照片。

所以照片是几MB的,我有一个回调函数返回

1KB直到它完成转移图片。

任何建议或示例我应该如何将图片放在一个变量中?

我听说有关使用内存池的事情,但我只需要这个场合简单的东西。

我可以使用CString吗?


无论如何,请提前感谢任何建议。

I have a situation where I''m getting a picture from a camera in small
chunks.
So the photo is a few MBytes and I have a callback function that returns
1KB until it finishes transfering the picture.
Any suggestions or examples how should I put a picture in one variable?
I heard something about using memory pools for this but I only need
something simple for this occasion.
Could I use CString?

Anyway thanks in advance for any suggestions.

推荐答案

Uli Kunkel< ge ******* @ yahoo.comwrites:
Uli Kunkel <ge*******@yahoo.comwrites:

我有一种情况,我正在用相机拍摄一张小照片。
块。

所以照片是几MB,我有一个回调函数

返回1KB,直到它完成转移图片。

任何建议或示例我应该如何将图片放入一个变量?

我听说过有关使用内存池的事情,但我只需要这个场合简单的东西。

我可以使用CString吗?
I have a situation where I''m getting a picture from a camera in small
chunks.
So the photo is a few MBytes and I have a callback function that
returns 1KB until it finishes transfering the picture.
Any suggestions or examples how should I put a picture in one variable?
I heard something about using memory pools for this but I only need
something simple for this occasion.
Could I use CString?



不在comp.lang.c ++上。对于CString,你应该在comp.lang.c上询问。

Not on comp.lang.c++. For CString, you should ask on comp.lang.c.


无论如何,请提前感谢任何建议。
Anyway thanks in advance for any suggestions.



typedef unsigned char byte;

const int KByte = 1024;

const int MByte = 1024 * KByte ;

const int few = 6;

std :: vector< byteimage(少* MByte,0);


然后你可以收到复制的小缓冲区:

std :: vector< byte> :: iterator pos = image.begin();

std :: vector< bytebuffer( 1 * KByte);


while(接收(&缓冲区)){

pos = std :: copy(buffer.begin(),buffer。结束(),pos);

}

-

__Pascal Bourguignon__


typedef unsigned char byte;
const int KByte=1024;
const int MByte=1024*KByte;
const int few=6;
std::vector<byteimage(few*MByte,0);

Then you can receive copy small buffers into it:
std::vector<byte>::iterator pos=image.begin();
std::vector<bytebuffer(1*KByte);

while(receive(&buffer)){
pos=std::copy(buffer.begin(),buffer.end(),pos);
}
--
__Pascal Bourguignon__


UliKunkelescribió:
Uli Kunkel escribió:

我有一种情况,我正在从相机中取出一张小块的b
块。 />
所以照片是几MB的,我有一个回调函数,返回

1KB,直到它完成转移图片。

任何建议或例子如何我应该把图片放在一个变量中吗?

我听说过关于使用内存池的问题,但我只需要这个场合的简单的东西。

我可以使用CString吗?


无论如何,提前感谢任何建议。
I have a situation where I''m getting a picture from a camera in small
chunks.
So the photo is a few MBytes and I have a callback function that returns
1KB until it finishes transfering the picture.
Any suggestions or examples how should I put a picture in one variable?
I heard something about using memory pools for this but I only need
something simple for this occasion.
Could I use CString?

Anyway thanks in advance for any suggestions.



使用向量,利用其reserve()函数。


#include< vector>


(...)

std :: vector< unsigned charmyPhoto;

myPhoto.reserve(1024 * 1024) ;


for(size_t part = 0; part!= 1024; ++ part){

<将图像数据读入& myPhoto(部分*) 1024)>

}

(...)

<你现在在myPhoto.size()顺序字节中有你的照片

& myPhoto [0]

只需根据您的确切需求定制这样的作品,用所有神奇的常量替换所有魔法

常数。 />
这个代码框架认为char大小是一个字节,你可以

需要更正它的代码否则


最好的问候,


Zara


Use a vector, taking advantage from its reserve() function.

#include <vector>

(...)

std::vector<unsigned charmyPhoto;
myPhoto.reserve(1024*1024);

for (size_t part=0; part !=1024;++part) {
<read image data into &myPhoto(part*1024) >
}
(...)
<you now have your photo in myPhoto.size() sequential bytes at
&myPhoto[0]
Just customize such piece for your exact needs, substsituting all magic
constants with nice real constants.
This code skeleton takes as granted that char size is one byte, you may
need to correct the code it it is otherwise

best regards,

Zara


Juan Antonio Zaratiegui Vallecillo写道:
Juan Antonio Zaratiegui Vallecillo wrote:

UliKunkelescribió:
Uli Kunkel escribió:

>我有一种情况,我正在用相机拍摄一张照片。
所以照片是几MB的,我有一个回调函数返回
1KB直到它完成转移图片。
任何建议或示例我应该如何将图片放在一个变量中?
我听说过有关使用内存池的事情,但我只是这个场合需要简单的东西。
我可以使用CString吗?

无论如何,请提前感谢任何建议。
>I have a situation where I''m getting a picture from a camera in small
chunks.
So the photo is a few MBytes and I have a callback function that returns
1KB until it finishes transfering the picture.
Any suggestions or examples how should I put a picture in one variable?
I heard something about using memory pools for this but I only need
something simple for this occasion.
Could I use CString?

Anyway thanks in advance for any suggestions.




使用向量,利用其reserve()函数。


#include< vector> ;


(...)

std :: vector< unsigned charmyPhoto;

myPhoto.reserve( (*尺寸:零件= 0;零件!= 1024; ++零件){

<读取图像数据&          myPhoto(part * 1024)>



Use a vector, taking advantage from its reserve() function.

#include <vector>

(...)

std::vector<unsigned charmyPhoto;
myPhoto.reserve(1024*1024);

for (size_t part=0; part !=1024;++part) {
<read image data into &myPhoto(part*1024) >



这应该是将数据附加到''myPhoto''。记住,保留

内存只是:保留内存。具体来说,它不是你可以覆盖的
对象。

This should read "append data to ''myPhoto''". Remember, reserved
memory is just that: reserved memory. Specifically, it''s not
objects you could overwrite.


[...]

Zara
[...]
Zara



Schobi

Schobi


这篇关于内存池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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