将内存分配给变量 [英] Allocating memory to a variable

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

问题描述

让我们说一个变量被声明为"var x".假设它占用动态内存,即SD RAM(同步动态RAM).如果我们从不实时使用该变量,那么如何保存该变量占用的内存?
(永远不使用的意思是,假设从外部端口获得一个变量Y和Z,如果我们获得输入,例如Y或Z,则Y有值或Z有值是随机的,但我们有内存只能容纳一个变量的空间,我们该怎么办?)

@ Kemp,yes.its相关的嵌入式DSP

Let''s say a variable is declared as "var x". Let''s assume it occupies dynamic memory, i.e., SD RAM (Synchronous Dynamic RAM). If we never use that variable in real time, how can we save the memory occupied by that variable?
(Meaning of never use in real time is,assume that there is a variables Y and Z,from the external ports if we get inputs,say Y or Z,it is random that either Y has value or Z has value but we have memory can accommodate only one variable''s space ,how can we do that?)

@Kemp,yes.its related embedded-DSP

推荐答案

如果从未使用过该变量,那么声明它的目的是什么?只是不要声明它.
If the variable is never used then what''s the point of declaring it? Just don''t declare it.


vidhyacharan写道:
vidhyacharan wrote:

让我们假设它占据了动态空间.内存

Let''s assume it occupies dynamic memory



这是您的问题上下文吗? :):



Would it be your question context ? :) :

void ANeverUsedFunction(int iInput)
{
  int iNeverUsedVar = iInput; // this on-stack variable
                              // will be never allocated
                              // if the function will be not called 
...
}


这里似乎存在一些术语问题.

通常,当谈论使用动态存储器作为变量的软件时,人们谈论的并不是变量存储在其中的物理类型.也就是说,人们谈论的不是动态RAM还是静态RAM或磁芯的使用.或者是其他东西.而是引用一种在运行时动态分配要用于变量的内存区域的方法,而不是在编译时确定性更高的方法设置.

现在,在C或C ++中,诸如int x;之类的变量定义虽然很可能存储在动态RAM中,但并未使用动态内存.两件事不同.

另外,我不确定我不要实时使用该变量的意思.
There seem to be some terminology issues here.

Generally, when talking about software using dynamic memory for a variable, one is not talking about the physical type of memory that the variable is stored in. That is, one is not talking about the use of dynamic RAM vs. static RAM or magnetic cores or something else. Instead, the reference is to a method of dynamically allocating a region of memory to be used for the variable at run time rather than a more deterministic method setup at compile time.

Now in C or C++, a variable definition such as int x; does not use dynamic memory, though it may well be stored in dynamic RAM. Two different things.

Also, I''m not sure I know what you mean by never use that variable in real time.


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

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