将数据集文件(十六进制值)读取到存储器部分2的块上 [英] Reading a dataset file(Hex values) onto a block of memory-part 2

查看:198
本文介绍了将数据集文件(十六进制值)读取到存储器部分2的块上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码块,试图将数据从数据集读取到随机分配的内存块。我不知道数据集里面究竟是什么,但他们访问矩阵值(十六进制值),并放在一个内存位置。

I have a block of code that is trying to read the data from a dataset on to a randomly allocated block of memory. I don't know what exactly is inside the dataset but they access matrix values(Hex values) and put on to a memory location. And it works perfectly fine!

const unsigned int img_size = numel_img * sizeof(float);// (1248*960)4bytes= 4.79MB   
for (unsigned int i=0; i<p_rctheader->glb_numImg; ++i)// 0 to 496(Total no of images)
{
    const unsigned int cur_proj = i; // absolute projection number

    // read proj mx
    double* const pProjMx = pProjMatrixBuffers + cur_proj * 12;
    ifsData.read((char*) (pProjMx), 12 * sizeof(double));
    ifsData.seekg(img_size, ios::cur); 
        }

其中pProjMatrixBuffers

where pProjMatrixBuffers is

double** pProjMatrixBuffers = new double* [rctheader.glb_numImg];   //
pProjMatrixBuffers[0] = new double[rctheader.glb_numImg * 12];  //
for (unsigned int i=1; i<rctheader.glb_numImg; ++i) {
    pProjMatrixBuffers[i] = pProjMatrixBuffers[0] + i * 12;
}

此后还有一个读操作:

rctgdata.adv_pProjBuffers = new float* [num_proj_buffers];// 124 buffers
rctgdata.adv_pProjBuffers[0] = new float[num_proj_buffers * numel_img];// (1.198MB per image*124)*4bytes
    // set it to zero
memset(rctgdata.adv_pProjBuffers[0], 0, num_proj_buffers * numel_img * sizeof(float));
for (unsigned int i=1; i<num_proj_buffers; ++i) {
rctgdata.adv_pProjBuffers[i] = rctgdata.adv_pProjBuffers[0] + i * numel_img;
}

for (unsigned int i=0; i<numProjsInIteration; ++i)// (0 to 124)
{
const unsigned int cur_proj = numProcessedProjs + i; // absolute projection number// 0+124->124+124->248+124->372+124

// read proj mx
ifsData.read((char*) (pProjMatrixBuffers[cur_proj]), 12 * sizeof(double));
 // read image data
ifsData.read((char*) (rctgdata.adv_pProjBuffers[i]), numel_img * sizeof(float));
}

em> * ** ** ** em> * ** ** *
基本上,此代码从数据集中读取投影矩阵,乘以1248 * 960图像像素(浮动)。这继续124次内循环。
Q1.如果你在上面的代码中看到,pProjMatrixBuffers [cur_proj]被读取两次,这可能已经做了一次。 (纠正我,如果我错了)。
Q2.如何知道rctgdata.adv_pProjBuffers [i]知道从哪里开始访问数据集中的数据?我的意思是数据集中的位置。对不起,如果我困惑你。如果需要,请向我询问更多信息。非常感谢所有的帮助!

******EDITS**************************** Basically this code, reads Projection matrix from the dataset which is 12 doubles followed by 1248*960 image pixels.(floats). This goes on for 124 times inside for loop. Q1.If you see in the above code, pProjMatrixBuffers[cur_proj] is read twice, which could have been done once. (Correct me if I am wrong). Q2.How will rctgdata.adv_pProjBuffers[i] know where to start accessing the data from in the dataset? I mean location in the dataset. I am sorry if I have confused you. Please ask me for more information if needed. Thank you so much for all the help in advance!!

推荐答案

没有办法二维MxN阵列可以使用新分配。此代码中的解决方法包括分配M指针的1维数组和MxN元素的另一个数组分配。然后,M指针被设置为指向数组中元素的每一行的M个第一元素。

There is no way a 2-dimensional MxN-array can be allocated as such using new. The workaround in this code consists of an allocation of a 1-dimensional array of M pointers and another allocation of an array for the MxN elements. Then the M pointers are set to point to the M first elements of each row within the array for the elements.

这里我们有两个二维数组,我调用显然的原因)D和F.不清楚D是多大 - rctheader.glb_numImg的值是多少?

Here we have two 2-dimensional arrays which I call (for obvious reasons) D and F. It's not clear how big D is - what's the value of rctheader.glb_numImg?

第一个循环读取12个双精度到一行D并跳过F行的浮点数据,执行具有适当正偏移量的seekg以添加到当前位置(即,向前)。这是做rctheader.glb_numImg次。

The first loop reads 12 doubles into a row of D and skips the float data for a row of F, doing a seekg with the appropriate positive offset to be added to the current position (i.e., forward). This is done rctheader.glb_numImg times.

有一些我在这段代码中看不到:单个seekg回到文件的开头,第一次循环后

There is something I don't see in this code: a single seekg back to the beginning of the file, after the first loop and before the second loop.

第二个循环读取(再一次)为124行中的每一行重复12次,然后,一次性重复1248 * 960次浮动每行。在这些读取之后不需要重新定位,因为第二图像的数据紧跟在第一图像的数据之后,等等。 (这有点刺激,num_proj_buffers和numProjsInIteration应该有相同的值,即124)。

The second loop reads (once more) 12 doubles for each of the 124 rows and then, in one fell swoop, 1248*960 floats for each row. There is no need to reposition after these reads since the data for the second image immediately follows the data for the first image, and so on. (It's slightly irritating that num_proj_buffers and numProjsInIteration should have the same value, i.e., 124.)

看起来好像第二个读循环将重读第一个循环读。但因为我不知道p_rctheader-> glb_numImg也是124,我不能真正地确认。

It looks as if the second read loop would re-read what the first loop read. But since I don't know for sure that p_rctheader->glb_numImg is also 124, I can't really confirm that.

计算123的读取大小第二个循环的迭代为

Calculating the size of what is read by 123 iterations of the second loop as

(1248*960*4 + 12*8)*124

这将占到〜0.5 GB - 但是文件大小报告为〜2.5 GB。

this would account for ~0.5 GB - but the file size was reported as being ~2.5 GB.

还要注意,第二个循环中的一个索引计算为

Also note that one index within the second loop is computed as

unsigned int cur_proj = numProcessedProjs + i;

但是numProcessedProjs的初始设置不清楚。

but the initial setting of numProcessedProjs is unclear.

这篇关于将数据集文件(十六进制值)读取到存储器部分2的块上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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