零阵列的快速方法

编程入门 行业动态 更新时间:2024-10-24 18:23:26
本文介绍了零阵列的快速方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

男人,那个头衔应该在一首诗中,但无论如何......所以,我有这个 程序,它有一个包含4000万个元素的数组。问题是 ,我有一个for循环,不断地对这个数组做什么, ,每次迭代,我都要把数组归零。这就是我现在这样做的方式://将lnscores归零(count = 0; count< chunksize; count ++)lnscores [count] = 0 ;有没有更快的方式 这样做?我知道必须要有一个技巧,因为这个阵列是一个很大的内存大块的内存吗?

解决方案

memset(lnscores,0,chunksize)

ro ********** @ gmail 认为:

男人,那个头衔应该在一首诗中,但无论如何......那么,我有这个程序,它有一个包含4000万个元素的数组。问题是我有一个for循环不断地对这个数组做什么,并且对于每次迭代,我必须将数组清零。这就是我目前正在做的事情://将lnscores清零(count = 0; count< chunksize; count ++)lnscores [count] = 0;有没有更快的方法来做到这一点?我知道必须有一个技巧,因为这个阵列是一个相当大的连续内存块吗?

如果你的阵列有文件范围你就不会甚至必须自己归零。 所有这些变量在启动时都归零。否则,声明它并且 初始化: int lnscores [WHATEVER_SIZE] = {0}; 如果你之后必须重新归零,你可以使用`memset()`。 - 世界被征服,星系被摧毁 - 但是一个女人永远是一个女人。 - 柯克,国王的良心,stardate unknown < ; http://clc-wiki/wiki/Introduction_to_comp.lang.c>

2006-05-12, ro ********** @ gmail < ro ********* *@gmail>写道:

男人,那个标题应该在一首诗中,但无论如何......所以,我有这个程序,它有一个包含4000万个元素的数组。问题是我有一个for循环不断地对这个数组做什么,并且对于每次迭代,我必须将数组清零。这就是我目前正在做的事情://将lnscores清零(count = 0; count< chunksize; count ++)lnscores [count] = 0;有没有更快的方法来做这个?我知道必须有一个技巧,因为这个数组是一个很大的连续内存块吗?

memset(lnscores,0,chunksize * sizeof lnscores [ 0]); 假设0代表0 ... lnscores是什么类型的?

Man, that title should be in a poem, but anyways...So, I have this program, and it has an array of 40 million elements. The problem is that I have a for loop that continually is doing stuff to this array, and for each iteration, I have to zero out the array. This is how I am currently doing it: // Zero out the lnscores for( count=0; count < chunksize; count++ ) lnscores[count] = 0; Is there no quicker way to do this? I know there must be a trick since this array is one big contiguous chunk of memory right?

解决方案

memset( lnscores, 0, chunksize )

ro**********@gmail opined:

Man, that title should be in a poem, but anyways...So, I have this program, and it has an array of 40 million elements. The problem is that I have a for loop that continually is doing stuff to this array, and for each iteration, I have to zero out the array. This is how I am currently doing it: // Zero out the lnscores for( count=0; count < chunksize; count++ ) lnscores[count] = 0; Is there no quicker way to do this? I know there must be a trick since this array is one big contiguous chunk of memory right?

If your array has file scope you don''t even have to zero it yourself. All such variables get zeroed at startup. Otherwise, declare it and initialise thus: int lnscores[WHATEVER_SIZE] = {0}; If you have to re-zero it afterwards, you could use `memset()`. -- Worlds are conquered, galaxies destroyed -- but a woman is always a woman. -- Kirk, "Conscience of the King", stardate unknown <clc-wiki/wiki/Introduction_to_comp.lang.c>

On 2006-05-12, ro**********@gmail <ro**********@gmail> wrote:

Man, that title should be in a poem, but anyways...So, I have this program, and it has an array of 40 million elements. The problem is that I have a for loop that continually is doing stuff to this array, and for each iteration, I have to zero out the array. This is how I am currently doing it: // Zero out the lnscores for( count=0; count < chunksize; count++ ) lnscores[count] = 0; Is there no quicker way to do this? I know there must be a trick since this array is one big contiguous chunk of memory right?

memset(lnscores, 0, chunksize * sizeof lnscores[0]); Assuming 0 is represented by 0... what type is lnscores?

更多推荐

零阵列的快速方法

本文发布于:2023-11-02 08:08:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阵列   快速   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!