C ++标准是否要求在continuousmemory中分配对象? [英] Does C++ standard require objects to be allocated in continuousmemory?

查看:113
本文介绍了C ++标准是否要求在continuousmemory中分配对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

嵌入式编程中的
,存在不同类型的内存,例如: RAM和

ROM(闪存)。对于包含变量和常量

值的类,可能需要将变量放在RAM中并将常量放在
ROM中,这意味着该对象被拆分为不同的部分

内存。


除了当前编译器不支持此类

功能之外:C ++标准是否需要对象数据

驻留在连续内存中(例如从此指针开始),或者可以将对象放在内存中的不同位置?


谢谢,


Uli

Hello,

in embedded programming, different kinds of memory exist, e.g. RAM and
ROM (Flash memory). For a class containing variables and constant
values one might want to put the variables in RAM and the constants in
ROM, which means that the object is split into different parts in
memory.

Besides from the fact that the current compiler does not support such
feature: does the C++ standard require an that the objects data
resides in continuous memory (e.g. starting from this pointer), or can
the object be put in different places in memory?

Thanks,

Uli

推荐答案

go **** @ margull.de 写道:
嵌入式编程中的
,存在不同种类的内存,例如RAM和

ROM(闪存)。对于包含变量和常量

值的类,可能需要将变量放在RAM中并将常量放在
ROM中,这意味着该对象被拆分为不同的部分

内存。


除了当前编译器不支持此类

功能之外:C ++标准是否需要对象数据

驻留在连续内存中(例如从这个指针开始),或者可以将对象放在内存中的不同位置?

in embedded programming, different kinds of memory exist, e.g. RAM and
ROM (Flash memory). For a class containing variables and constant
values one might want to put the variables in RAM and the constants in
ROM, which means that the object is split into different parts in
memory.

Besides from the fact that the current compiler does not support such
feature: does the C++ standard require an that the objects data
resides in continuous memory (e.g. starting from this pointer), or can
the object be put in different places in memory?



是的,它要求对象占用连续的内存部分。

这就是对象的定义方式。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

Yes, it requires that objects occupy a contiguous memory portion.
That''s how an object is defined.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


8月12日下午3:58,goo ... @ margull.de写道:嵌入式编程中
On Aug 12, 3:58 pm, goo...@margull.de wrote:

,存在不同类型的存储器,例如:
RAM和ROM(闪存)。对于包含变量

和常量值的类,可能需要将变量放入RAM

和ROM中的常量,这意味着对象被拆分

到内存中的不同部分。


除了当前编译器不支持
支持这样的功能:C ++标准是否需要

对象数据驻留在连续内存中(例如从此指针开始

),或者可以将对象放在不同的

位置记忆?
in embedded programming, different kinds of memory exist, e.g.
RAM and ROM (Flash memory). For a class containing variables
and constant values one might want to put the variables in RAM
and the constants in ROM, which means that the object is split
into different parts in memory.

Besides from the fact that the current compiler does not
support such feature: does the C++ standard require an that
the objects data resides in continuous memory (e.g. starting
from this pointer), or can the object be put in different
places in memory?



这取决于。如果常量是静态成员,则可以在任何地方使用
。 (如果他们不是,他们就不会保持不变,直到

构造函数完成运行,所以很明显他们不能把b
放到ROM中除了Victor指出的问题之外。)


-

James Kanze(GABI软件)电子邮件:ja ******** *@gmail.com

Conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9placeSémard,78210 St.-Cyr-l ''école,法国,+ 33(0)1 30 23 00 34

It depends. If the constants are static members, they can be
anywhere. (If they''re not, they won''t be constant until after
the constructor has finished running, so obviously they can''t be
put into ROM. In addition to the issue Victor pointed out.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


< go **** @ margull.dewrote in message news:33 *** ******************************* @ k30g2000 hse.googlegroups.com ...
<go****@margull.dewrote in message news:33**********************************@k30g2000 hse.googlegroups.com...

你好,

嵌入式编程中的
,存在不同类型的内存,例如RAM和

ROM(闪存)。对于包含变量和常量

值的类,可能需要将变量放在RAM中并将常量放在
ROM中,这意味着该对象被拆分为不同的部分

内存。


除了当前编译器不支持此类

功能之外:C ++标准是否需要对象数据

驻留在连续内存中(例如从这个指针开始),或者可以将对象放在内存中的不同位置?

Hello,

in embedded programming, different kinds of memory exist, e.g. RAM and
ROM (Flash memory). For a class containing variables and constant
values one might want to put the variables in RAM and the constants in
ROM, which means that the object is split into different parts in
memory.

Besides from the fact that the current compiler does not support such
feature: does the C++ standard require an that the objects data
resides in continuous memory (e.g. starting from this pointer), or can
the object be put in different places in memory?



常量将被定义为静态范围。在这种情况下,它们将被存储一次而不是每个实例。将它们标记为const将进一步允许编译器/链接器优化它们在只读存储中的位置。

MS Visual C ++现在支持这一点。非静态类数据被放置在堆上,连续地,静态数据被放置在EXE映像中的一个部分中,当映射到内存时,它将适当地为R-only或RW。我确定其他当前的c ++开发环境也做类似的事情。

The constants would be defined as statically scoped. In which case they will be stored once rather than per instance. Marking them as const would futher allow the compiler / linker to optimize their placement into read only storage.
MS Visual C++ supports this right now. non static class data is placed on the heap, contiguously, static data is placed in the EXE image in a section that, when mapped into memory, will be R-only or RW as appropriate. Im sure other current c++ dev environments do similar things.


这篇关于C ++标准是否要求在continuousmemory中分配对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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