有一个大阵列 [英] Having a large array

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

问题描述

你好,


我想拥有一个大阵列。我有一个包含6个字段的结构,其中4个是unsigned char,其中2个是unsigned short。我应该有一个包含上述结构类型的80个元素的数组。我想把它作为一个类中的静态数组,我可以参考这个类中的任何函数。我正在为高级音频放大器(嵌入式系统)编程,在PowerPC和OSEK RTOS上运行。编译器是diab。当我使用60个元素声明数组时,它工作正常,但当我将其增加到80个元素时,目标系统由于内存不足而无法启动。在C ++中是否有任何方法可以让它工作? (我已将数组声明为const,否则代码不会编译)


谢谢,


问候,

Ramu

解决方案

对于star5t,我通常不会调用640字节的数组。然而,由于这是一个嵌入式系统(而不是具有和超出资源的PC),它取决于你有多少板载RAM。


如果你的RAM用完了那么C ++没有什么可以做的,它不能神奇地让你的RAM能够包含更多的数据。你有一些选择

  1. 寻找RAM的低效使用并消除这种情况。这可能是比需要更长的数组(在1个案例中,我使用了2个60kbyte数组,但没有使用)或确保定义了结构和类,因此它们将数据有效地打包到RAM中,浪费的空间很小(我只需要重新排序1800个元素阵列中使用的结构中的元素,就可以节省大约8千字节。)
  2. 查找暂时使用数据的程序部分,看看是否可以将程序重新编写为让他们与程序的另一部分共享数据或使用堆。
  3. 检查堆栈和堆的大小,看它们是否可以更小。不幸的是,在这方面,C ++往往需要比C更大的堆。


谢谢Banfa ..将根据您的建议进行检查。

同时,我想问一下C ++中是否有不同的编程方案?


@ pram29


如果剩下那么小的RAM(< 80 * 8字节),我就不会用C ++编程了;也许C可以把它塞进这么小的内存中,但我担心你不得不求助于汇编语言。


亲切的问候,



Hello,

I want to have a large array. I have a structure which contains 6 fields, 4 of them are unsigned char and 2 of them are unsigned short. I should have an array of 80 elements of type the above said structure. I would like to have it as a static array in a class, which I can refer to, from any function inside this class. I am programming this for an advanced audio amplifier (Embedded system), running on PowerPC and OSEK RTOS. compiler is diab. When I declared the array with 60 elements, it worked fine, but when I increased it to 80 elements, the target system is not booting because of insuffiecient RAM. Is there any way in C++ so that I can make it work? (I have declared the array as const, otherwise the code wont compile)

Thanks,

Regards,
Ramu

解决方案

To star5t with I would not normally call an array of 640 bytes big. However since this is an embedded system (rather than a PC with and excess of resources) it rather depends on how much on board RAM you have.

If you have run out of RAM then there is nothing C++ can do, it can not magically make your RAM able to contain more data. You have some options

  1. Look for inefficient use of RAM and eliminate this. This could be arrays that are longer than need be (in in 1 case I worked on 2 60kbyte arrays that just weren''t used) or making sure you structures and classes are defined so they pack the data efficiently into RAM with little wasted space (I save about 8kbytes once just re-ordering the elements in a structure used in an array of 1800 elements).
  2. Look for potions of the program that use data temporarily, see if you can rework the program to let them share data with another portion of the program or use the heap.
  3. Check the size of your stack and heap see if they could be smaller. Unfortunately C++ tends to require a bigger heap than C in this respect.


Thank you Banfa.. Will have a check according to your suggestion.
Meanwhile, I would like to ask if there is a different way in C++ to program this scenario?


@pram29
If you have that little RAM left (< 80*8 bytes) I wouldn''t program in C++ at all; maybe C can cram it in such little RAM but I''m afraid you have to resort to assembly language.

kind regards,

Jos


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

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